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)
13720정성태8/29/202412524VS.NET IDE: 193. C# - Visual Studio의 자식 프로세스 디버깅
13719정성태8/28/202411608Linux: 79. C++ - pthread_mutexattr_destroy가 없다면 메모리 누수가 발생할까요?
13718정성태8/27/202414253오류 유형: 921. Visual C++ - error C1083: Cannot open include file: 'float.h': No such file or directory [2]
13717정성태8/26/202414553VS.NET IDE: 192. Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드
13716정성태8/21/202412314C/C++: 167. Visual C++ - 윈도우 환경에서 _execv 동작 [1]
13715정성태8/19/202414916Linux: 78. 리눅스 C/C++ - 특정 버전의 glibc 빌드 (docker-glibc-builder)
13714정성태8/19/202412456닷넷: 2295. C# 12 - 기본 생성자(Primary constructors) (책 오타 수정) [3]
13713정성태8/16/202415462개발 환경 구성: 721. WSL 2에서의 Hyper-V Socket 연동
13712정성태8/14/202413232개발 환경 구성: 720. Synology NAS - docker 원격 제어를 위한 TCP 바인딩 추가
13711정성태8/13/202414334Linux: 77. C# / Linux - zombie process (defunct process) [1]파일 다운로드1
13710정성태8/8/202415540닷넷: 2294. C# 13 - (6) iterator 또는 비동기 메서드에서 ref와 unsafe 사용을 부분적으로 허용파일 다운로드1
13709정성태8/7/202413280닷넷: 2293. C# - safe/unsafe 문맥에 대한 C# 13의 (하위 호환을 깨는) 변화파일 다운로드1
13708정성태8/7/202414175개발 환경 구성: 719. ffmpeg / YoutubeExplode - mp4 동영상 파일로부터 Audio 파일 추출
13707정성태8/6/202413758닷넷: 2292. C# - 자식 프로세스의 출력이 4,096보다 많은 경우 Process.WaitForExit 호출 시 hang 현상파일 다운로드1
13706정성태8/5/202412991개발 환경 구성: 718. Hyper-V - 리눅스 VM에 새로운 디스크 추가
13705정성태8/4/202413582닷넷: 2291. C# 13 - (5) params 인자 타입으로 컬렉션 허용 [2]파일 다운로드1
13704정성태8/2/202415004닷넷: 2290. C# - 간이 dotnet-dump 프로그램 만들기파일 다운로드1
13703정성태8/1/202413504닷넷: 2289. "dotnet-dump ps" 명령어가 닷넷 프로세스를 찾는 방법
13702정성태7/31/202414752닷넷: 2288. Collection 식을 지원하는 사용자 정의 타입을 CollectionBuilder 특성으로 성능 보완파일 다운로드1
13701정성태7/30/202416311닷넷: 2287. C# 13 - (4) Indexer를 이용한 개체 초기화 구문에서 System.Index 연산자 허용파일 다운로드1
13700정성태7/29/202415447디버깅 기술: 200. DLL Export/Import의 Hint 의미
13699정성태7/27/202416181닷넷: 2286. C# 13 - (3) Monitor를 대체할 Lock 타입파일 다운로드1
13698정성태7/27/202414738닷넷: 2285. C# - async 메서드에서의 System.Threading.Lock 잠금 처리파일 다운로드1
13697정성태7/26/202413189닷넷: 2284. C# - async 메서드에서의 lock/Monitor.Enter/Exit 잠금 처리파일 다운로드1
13696정성태7/26/202413917오류 유형: 920. dotnet publish - error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for '...'
13695정성태7/25/202413518닷넷: 2283. C# - Lock / Wait 상태에서도 STA COM 메서드 호출 처리파일 다운로드1
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...