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)
13089정성태6/28/202221859개발 환경 구성: 646. HOSTS 파일 변경 시 Edge 브라우저에 반영하는 방법
13088정성태6/27/202220273개발 환경 구성: 645. "Developer Command Prompt for VS 2022" 명령행 환경의 폰트를 바꾸는 방법
13087정성태6/23/202223012스크립트: 41. 파이썬 - FastAPI / uvicorn 호스팅 환경에서 asyncio 사용하는 방법 [1]
13086정성태6/22/202224449.NET Framework: 2026. C# 11 - 문자열 보간 개선 2가지파일 다운로드1
13085정성태6/22/202222223.NET Framework: 2025. C# 11 - 원시 문자열 리터럴(raw string literals)파일 다운로드1
13084정성태6/21/202222687개발 환경 구성: 644. Windows - 파이썬 2.7을 msi 설치 없이 구성하는 방법
13083정성태6/20/202222589.NET Framework: 2024. .NET 7에 도입된 GC의 메모리 해제에 대한 segment와 region의 차이점 [2]
13082정성태6/19/202222514.NET Framework: 2023. C# - Process의 I/O 사용량을 보여주는 GetProcessIoCounters Win32 API파일 다운로드1
13081정성태6/17/202220654.NET Framework: 2022. C# - .NET 7 Preview 5 신규 기능 - System.IO.Stream ReadExactly / ReadAtLeast파일 다운로드1
13080정성태6/17/202222643개발 환경 구성: 643. Visual Studio 2022 17.2 버전에서 C# 11 또는 .NET 7.0 preview 적용
13079정성태6/17/202219328오류 유형: 814. 파이썬 - Error: The file/path provided (...) does not appear to exist
13078정성태6/16/202222959.NET Framework: 2021. WPF - UI Thread와 Render Thread파일 다운로드1
13077정성태6/15/202225171스크립트: 40. 파이썬 - PostgreSQL 환경 구성
13075정성태6/15/202221772Linux: 50. Linux - apt와 apt-get의 차이 [2]
13074정성태6/13/202220902.NET Framework: 2020. C# - NTFS 파일에 사용자 정의 속성값 추가하는 방법파일 다운로드1
13073정성태6/12/202222007Windows: 207. Windows Server 2022에 도입된 WSL 2
13072정성태6/10/202222597Linux: 49. Linux - ls 명령어로 출력되는 디렉터리 색상 변경 방법
13071정성태6/9/202223730스크립트: 39. Python에서 cx_Oracle 환경 구성
13070정성태6/8/202223238오류 유형: 813. Windows 11에서 입력 포커스가 바뀌는 문제 [1]
13069정성태5/26/202226647.NET Framework: 2019. C# - .NET에서 제공하는 3가지 Timer 비교 [2]
13068정성태5/24/202224176.NET Framework: 2018. C# - 일정 크기를 할당하는 동안 GC를 (가능한) 멈추는 방법 [1]파일 다운로드1
13067정성태5/23/202220528Windows: 206. Outlook - 1년 이상 지난 메일이 기본적으로 안 보이는 문제
13066정성태5/23/202221138Windows: 205. Windows 11 - Windows + S(또는 Q)로 뜨는 작업 표시줄의 검색 바가 동작하지 않는 경우
13065정성태5/20/202223029.NET Framework: 2017. C# - Windows I/O Ring 소개 [2]파일 다운로드1
13064정성태5/18/202221893.NET Framework: 2016. C# - JIT 컴파일러의 인라인 메서드 처리 유무
13063정성태5/18/202222557.NET Framework: 2015. C# - 인라인 메서드(inline methods)
... 31  32  33  34  35  36  37  38  [39]  40  41  42  43  44  45  ...