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

비밀번호

댓글 작성자
 




... 16  17  18  [19]  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13593정성태4/8/202413622닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/202416797C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동 [1]
13591정성태4/2/202415518닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/202415335Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/202414465닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
13588정성태3/28/202417464닷넷: 2232. C# - Unity + 닷넷 App(WinForms/WPF) 간의 Named Pipe 통신 [2]파일 다운로드1
13587정성태3/27/202414470오류 유형: 900. Windows Update 오류 - 8024402C, 80070643
13586정성태3/27/202419998Windows: 263. Windows - 복구 파티션(Recovery Partition) 용량을 늘리는 방법
13585정성태3/26/202415956Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/202418965개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법 [9]파일 다운로드1
13583정성태3/25/202415112Windows: 261. CPU Utilization이 100% 넘는 경우를 성능 카운터로 확인하는 방법
13582정성태3/19/202418068Windows: 260. CPU 사용률을 나타내는 2가지 수치 - 사용량(Usage)과 활용률(Utilization)파일 다운로드1
13581정성태3/18/202416055개발 환경 구성: 707. 빌드한 Unity3D 프로그램을 C++ Windows Application에 통합하는 방법
13580정성태3/15/202414875닷넷: 2231. C# - ReceiveTimeout, SendTimeout이 적용되지 않는 Socket await 비동기 호출파일 다운로드1
13579정성태3/13/202417547오류 유형: 899. HTTP Error 500.32 - ANCM Failed to Load dll
13578정성태3/11/202418791닷넷: 2230. C# - 덮어쓰기 가능한 환형 큐 (Circular queue)파일 다운로드1
13577정성태3/9/202417748닷넷: 2229. C# - 닷넷을 위한 난독화 도구 소개 (예: ConfuserEx)
13576정성태3/8/202417022닷넷: 2228. .NET Profiler - IMetaDataEmit2::DefineMethodSpec 사용법
13575정성태3/7/202419305닷넷: 2227. 최신 C# 문법을 .NET Framework 프로젝트에 쓸 수 있을까요?
13574정성태3/6/202417469닷넷: 2226. C# - "Docker Desktop for Windows" Container 환경에서의 IPv6 DualMode 소켓
13573정성태3/5/202416203닷넷: 2225. Windbg - dumasync로 분석하는 async/await 호출
13572정성태3/4/202415272닷넷: 2224. C# - WPF의 Dispatcher Queue로 알아보는 await 호출의 hang 현상파일 다운로드1
13571정성태3/1/202415542닷넷: 2223. C# - await 호출과 WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13570정성태2/29/202416962닷넷: 2222. C# - WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13569정성태2/28/202416043닷넷: 2221. C# - LoadContext, LoadFromContext 그리고 GAC파일 다운로드1
13568정성태2/27/202417751닷넷: 2220. C# - .NET Framework 프로세스의 LoaderOptimization 설정을 확인하는 방법파일 다운로드1
... 16  17  18  [19]  20  21  22  23  24  25  26  27  28  29  30  ...