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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  13  14  [15]  ...
NoWriterDateCnt.TitleFile(s)
13695정성태7/25/202413518닷넷: 2283. C# - Lock / Wait 상태에서도 STA COM 메서드 호출 처리파일 다운로드1
13694정성태7/25/202413403닷넷: 2282. C# - ASP.NET Core Web App의 Request 용량 상한값 (Kestrel, IIS)
13693정성태7/24/202413114개발 환경 구성: 717. Visual Studio - C# 프로젝트에서 레지스트리에 등록하지 않은 COM 개체 참조 및 사용 방법파일 다운로드1
13692정성태7/24/202415132디버깅 기술: 199. Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색
13691정성태7/23/202413969디버깅 기술: 198. Windbg - 스레드의 Win32 Message Queue 정보 조회
13690정성태7/23/202412047오류 유형: 919. Visual C++ 리눅스 프로젝트 - error : ‘u8’ was not declared in this scope
13689정성태7/22/202415794디버깅 기술: 197. Windbg - PE 포맷의 Export Directory 탐색
13688정성태7/21/202412808닷넷: 2281. C# - Lock / Wait 상태에서도 일부 Win32 메시지 처리파일 다운로드1
13687정성태7/19/202414753닷넷: 2280. C# - PostThreadMessage로 보낸 메시지를 Windows Forms에서 수신하는 방법파일 다운로드1
13686정성태7/19/202414266오류 유형: 918. Visual Studio - ATL Simple Object 추가 시 error C2065: 'IDR_...': undeclared identifier
13685정성태7/19/202413807스크립트: 66. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법 - 두 번째 이야기
13684정성태7/19/202414478닷넷: 2279. C# - 문자열 보간식 사례 (예: 조건 연산자 사용)
13683정성태7/18/202412878오류 유형: 917. ClrMD - Linux 환경의 .NET 5 덤프 분석 시 hang 현상
13682정성태7/18/202413622닷넷: 2278. WPF - 스레드에 종속되는 DependencyObject파일 다운로드1
13681정성태7/17/202413877닷넷: 2277. C# 13 - (2) 메서드 그룹의 자연 타입 개선 (메서드 추론 개선)파일 다운로드1
13680정성태7/16/202414836닷넷: 2276. C# - Method Group, Natural Type, function_type파일 다운로드1
13679정성태7/16/202411780Linux: 76. Linux - C++ (getaddrinfo 등을 담고 있는) libnss 정적 링크
13678정성태7/15/202413553VS.NET IDE: 191. Visual Studio 2022 - .NET 5 프로젝트를 Docker Support로 실행했을 때 오류
13677정성태7/15/202414135오류 유형: 916. MSBuild - CheckEolTargetFramework (warning NETSDK1138)
13676정성태7/14/202413848Linux: 75. gdb에서 glibc의 함수에 Breakpoint 걸기
13675정성태7/13/202417907C/C++: 166. C/C++ - DLL에서 template 함수를 export하는 방법 [1]파일 다운로드1
13674정성태7/13/202415411오류 유형: 915. Unhandled Exception: Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: Unable to connect to Process
13673정성태7/11/202417708닷넷: 2275. C# 13 - (1) 신규 이스케이프 시퀀스 '\e'파일 다운로드1
13672정성태7/10/202413634닷넷: 2274. IIS - (프로세스 종료 없는) AppDomain Recycle
13671정성태7/10/202413403오류 유형: 914. Package ca-certificates is not installed.
13669정성태7/9/202413068오류 유형: 913. C# - AOT StaticExecutable 정적 링킹 시 빌드 오류
1  2  3  4  5  6  7  8  9  10  11  12  13  14  [15]  ...