Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

(시리즈 글이 4개 있습니다.)
개발 환경 구성: 259. Visual Studio 없이 Visual C++ 컴파일하는 방법
; https://www.sysnet.pe.kr/2/0/2879

개발 환경 구성: 323. Visual Studio 설치 없이 빌드 환경 구성 - Visual Studio 2017용 Build Tools
; https://www.sysnet.pe.kr/2/0/11275

오류 유형: 536. Visual Studio - "Developer Pack"을 설치했는데도 "대상 프레임워크" 목록에 나오지 않는 경우
; https://www.sysnet.pe.kr/2/0/11897

개발 환경 구성: 755. Visual Studio 2022/2026 - .NET Framework 2.x ~ 4.x 프로젝트 빌드 방법
; https://www.sysnet.pe.kr/2/0/14043




Visual Studio 2022/2026 - .NET Framework 2.x ~ 4.x 프로젝트 빌드 방법

Visual Studio 2022/2026만을 설치하면, 기존의 .NET Framework 4.0, 4.5를 대상으로 한 프로젝트의 로드/빌드 시 오류가 발생합니다.

netfx_4_dev_pack_1.png

(3.5 버전의 dev tools도 있으면서 왜 4.0은 누락시켰는지... ^^;)

그래서, 예를 들어 .NET 4.0을 대상으로 한 C# 프로젝트를 로드하는 경우,

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{FF58DC5A-9D23-4586-97DB-D3117D9E5C85}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <!-- ...[생략]... ->
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

이런 창이 뜨면서 4.8로 업그레이드할 것을 요구합니다.

netfx_4_dev_pack_2.png

Target framework not supported

The C# project ConsoleApp1 targets .NET Framework 4.0, which is no longer supported. While you can change your target framework at any time, for stability and security we recommend that you move to a recent supported release.

() Update the target to .NET Framework 4.8 (Recommended)
() Download .NET Framework 4.0 targeting pack (opens in browser)
() Do not load this project

만약 두 번째 옵션을 선택하면 https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk 링크를 방문하는데, ".NET Framework" / "Out of support versions" 영역을 봐도, .NET 4.0/4.5에 대해서는 "개발자 팩(Developer Pack)"은 볼 수 없고 "Reference assemblies" 문서 페이지로만 연결이 됩니다.

Build apps against Microsoft.NETFramework.ReferenceAssemblies
; https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/reference-assemblies

다소 불편하긴 해도, 다행히 빌드할 수 있는 방법은 열어둔 것입니다. ^^




문서 내용을 간단하게 정리해 볼까요? ^^ 일단, 현재 상태에서는 Visual Studio는 물론이고 명령행에서도 빌드가 안 됩니다.

C:\temp\ConsoleApp1\ConsoleApp1> dotnet build
Restore complete (0.2s)
  ConsoleApp1 failed with 1 error(s) (0.0s)
    C:\Program Files\dotnet\sdk\10.0.100\Microsoft.Common.CurrentVersion.targets(1259,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Build failed with 1 error(s) in 0.5s

여기서 필요한 작업이 오직 명령행 빌드라면, (예를 들어 빌드 서버처럼) 이런 경우 csproj에 다음과 같이 패키지 참조만 넣어두면 됩니다.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{FF58DC5A-9D23-4586-97DB-D3117D9E5C85}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
  </ItemGroup>

  <!-- ...[생략]... ->
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

그럼, (restore 과정을 지나) 빌드가 잘 됩니다.

C:\temp\ConsoleApp1\ConsoleApp1> dotnet build
Restore complete (1.1s)
  ConsoleApp1 succeeded with 1 warning(s) (1.7s) → c:\temp\builds\ConsoleApp1\AnyCPU\Debug\ConsoleApp1.exe
    C:\Program Files\dotnet\sdk\10.0.100\Microsoft.Common.CurrentVersion.targets(2437,5): warning MSB3267: The primary reference "System.Net.Http", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Net.Http" or retarget your application to a framework version which contains "System.Net.Http".

Build succeeded with 1 warning(s) in 3.0s




이렇게 명령행에서 빌드는 되었지만, 여전히 저 프로젝트는 비주얼 스튜디오에서 로드가 안 됩니다. 이것을 가능하게 만드는 방법을 아래의 글에서 잘 소개하고 있는데요,

Building a project that target .NET Framework 4.5 in Visual Studio 2022
; https://thomaslevesque.com/2021/11/12/building-a-project-that-target-net-45-in-visual-studio-2022/

Open Legacy Projects (4.5 Framework) In Visual Studio 2022
; https://www.c-sharpcorner.com/article/open-legacy-projects-4-5-framework-in-visual-studio-2022/

예를 들어, 이번 글에서는 .NET Framework 4.0 프로젝트를 빌드하는 것이므로 아래의 패키지를 다운로드하면 됩니다.

Microsoft.NETFramework.ReferenceAssemblies.net40
; https://www.nuget.org/packages/Microsoft.NETFramework.ReferenceAssemblies.net40/

// 만약 4.5 프로젝트라면,
Microsoft.NETFramework.ReferenceAssemblies.net40
; https://www.nuget.org/packages/Microsoft.NETFramework.ReferenceAssemblies.net45/

그런 다음 압축을 해제해야 하는데요, 제 경우에는 간단하게 ".zip" 확장자만 붙여서,

microsoft.netframework.referenceassemblies.net40.1.0.3.nupkg
==> microsoft.netframework.referenceassemblies.net40.1.0.3.nupkg.zip

윈도우 탐색기를 이용해 압축을 풀었습니다. 이후, 그 결과물을 비주얼 스튜디오가 인식하는 경로로 복사(덮어쓰기)해야 하는데요, 가령, nupkg 파일의 압축을 "c:\temp"에 풀었다면 그 하위인 "build\.NETFramework\v4.0" 디렉터리의 모든 내용을,

c:\temp\build\.NETFramework\v4.0

아래의 경로에 그대로 복사하면 됩니다.

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0

// 만약 4.5 버전이라면,
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5

마지막으로 비주얼 스튜디오에서 다시 .NET Framework 4.0 프로젝트를 열면,

[4.0 프로젝트를 각각 Visual Studio 2022와 2026 버전에서 로드]
netfx_4_dev_pack_3.png

로드 및 빌드가 정상적으로 이뤄집니다. 또한, 새 프로젝트를 생성할 때에도 새롭게 ".NET Framework 4"부터 시작해 "4.5.1", "4.5.2" 항목이 인식돼 선택이 가능합니다.

netfx_4_dev_pack_4.png

참고로, NuGet에서 배포하는 Microsoft.NETFramework.ReferenceAssemblies 패키지 정보를 보면, .NET Framework 2.0 ~ 4.8.1까지 모두 지원하는 것을 볼 수 있습니다. (즉, .NET Framework 전체 버전에 대해 저런 추가 설정이 가능한 것입니다.) 또한, 이런 식으로 nupkg 압축을 풀어 복사한 경우에는 csproj에 PackageReference 설정을 하지 않아도 무방합니다.




위에서 예를 든 빌드의 경우 System.Net.Http 어셈블리를 찾을 수 없다는 경고가 나왔는데요,

warning MSB3267: The primary reference "System.Net.Http", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Net.Http" or retarget your application to a framework version which contains "System.Net.Http".


해당 프로젝트를 Visual Studio 2022(또는 2026)에서 4.6+ 대상으로 만들었기 때문에 System.Net.Http 어셈블리 참조가 기본적으로 포함돼 있어 발생하는 것입니다. 따라서, csproj 파일을 열어 해당 항목만 삭제하면,

<Reference Include="System.Net.Http" />

이후 경고가 발생하지 않습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 11/13/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
13114정성태8/2/202225114.NET Framework: 2039. C# - Task와 비교해 본 ValueTask 사용법파일 다운로드1
13113정성태7/31/202224338.NET Framework: 2038. C# 11 - Span 타입에 대한 패턴 매칭 (Pattern matching on ReadOnlySpan<char>)
13112정성태7/30/202226300.NET Framework: 2037. C# 11 - 목록 패턴(List patterns) [1]파일 다운로드1
13111정성태7/29/202225820.NET Framework: 2036. C# 11 - IntPtr/UIntPtr과 nint/nuint의 통합파일 다운로드1
13110정성태7/27/202223295.NET Framework: 2035. C# 11 - 새로운 연산자 ">>>" (Unsigned Right Shift)파일 다운로드1
13109정성태7/27/202225371VS.NET IDE: 177. 비주얼 스튜디오 2022를 이용한 (소스 코드가 없는) 닷넷 모듈 디버깅 - "외부 원본(External Sources)" [1]
13108정성태7/26/202223392Linux: 53. container에 실행 중인 Golang 프로세스를 디버깅하는 방법 [1]
13107정성태7/25/202226347Linux: 52. Debian/Ubuntu 계열의 docker container에서 자주 설치하게 되는 명령어 [1]
13106정성태7/24/202220370오류 유형: 819. 닷넷 6 프로젝트의 "Conditional compilation symbols" 기본값 오류
13105정성태7/23/202225116.NET Framework: 2034. .NET Core/5+ 환경에서 (프로젝트가 아닌) C# 코드 파일을 입력으로 컴파일하는 방법 - 두 번째 이야기 [1]
13104정성태7/23/202229082Linux: 51. WSL - init에서 systemd로 전환하는 방법
13103정성태7/22/202223716오류 유형: 818. WSL - systemd-genie와 관련한 2가지(systemd-remount-fs.service, multipathd.socket) 에러
13102정성태7/19/202223373.NET Framework: 2033. .NET Core/5+에서는 구할 수 없는 HttpRuntime.AppDomainAppId
13101정성태7/15/202237845도서: 시작하세요! C# 10 프로그래밍
13100정성태7/15/202225529.NET Framework: 2032. C# 11 - shift 연산자 재정의에 대한 제약 완화 (Relaxing Shift Operator)
13099정성태7/14/202223277.NET Framework: 2031. C# 11 - 사용자 정의 checked 연산자파일 다운로드1
13098정성태7/13/202220978개발 환경 구성: 647. Azure - scale-out 상태의 App Service에서 특정 인스턴스에 요청을 보내는 방법 [1]
13097정성태7/12/202220767오류 유형: 817. Golang - binary.Read: invalid type int32
13096정성태7/8/202223696.NET Framework: 2030. C# 11 - UTF-8 문자열 리터럴
13095정성태7/7/202220818Windows: 208. AD 도메인에 참여하지 않은 컴퓨터에서 Kerberos 인증을 사용하는 방법
13094정성태7/6/202219340오류 유형: 816. Golang - "short write" 오류 원인
13093정성태7/5/202220471.NET Framework: 2029. C# - HttpWebRequest로 localhost 접속 시 2초 이상 지연
13092정성태7/3/202223660.NET Framework: 2028. C# - HttpWebRequest의 POST 동작 방식파일 다운로드1
13091정성태7/3/202223456.NET Framework: 2027. C# - IPv4, IPv6를 모두 지원하는 서버 소켓 생성 방법 [1]
13090정성태6/29/202222866오류 유형: 815. PyPI에 업로드한 패키지가 반영이 안 되는 경우
13089정성태6/28/202221859개발 환경 구성: 646. HOSTS 파일 변경 시 Edge 브라우저에 반영하는 방법
... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...