Visual Studio 2010을 통한 .NET Framework 4.5 대상 지정
오늘은 Visual Studio 2010에서 사용할 수있을 것으로 기대되는 컴퓨터에 .NET Framework 4.5를 설치했습니다. Visual Studio 2010에서는 문제가되지 않는 사소한 업데이트 일뿐입니다. 불행히도 특정 4.0을 수동으로 제거하지도 않습니다. 해당 4.5 어셈블리를 추가하면 원래 4.0 어셈블리가 여전히 프로젝트에서 참조됩니다.
Visual Studio 2010에서 버전 4.5를 대상으로 할 수 있습니까? 그렇다면 그렇다면 어떻게해야합니까? 리본을 정말로 사용하고 싶습니다 ...
Visual Studio 2010 이전의 각 버전의 Visual Studio는 특정 .NET 프레임 워크에 연결되어 있습니다. (VS2008은 .NET 3.5, VS2005는 .NET 2.0, VS2003은 .NET1.1입니다.) Visual Studio 2010 이상에서는 이전 프레임 워크 버전을 대상으로 지정할 수 있지만 이후 릴리스에는 사용할 수 없습니다. .NET 4.5를 사용하려면 Visual Studio 2012를 사용해야합니다.
이것이 유용한 곳을 생각할 수있는 시나리오는 매우 제한적이지만 VS2012 또는 그 효과를 구매할 자금을 얻을 수 없다고 가정 해 봅시다. 이 경우 Windows 7 + 및 VS 2010을 사용하는 경우 다음 해킹을 사용할 수 있습니다. 작동하는 것처럼 보입니다 (그러나이 방법을 사용하여 응용 프로그램을 아직 완전히 배포하지는 않았습니다).
프로젝트 파일을 백업하십시오 !!!
.NET 4.5 SDK가 포함 된 Windows 8 SDK 를 다운로드하여 설치하십시오 .
VS2010에서 프로젝트를 엽니 다.
프로젝트
Compile_4_5_CSharp.targets
에 다음 내용으로 이름이 지정된 텍스트 파일을 작성하십시오 . (또는 여기에서 다운로드 하십시오 . 파일 이름에서 ".txt"확장자를 제거하십시오) :<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- Change the target framework to 4.5 if using the ".NET 4.5" configuration --> <PropertyGroup Condition=" '$(Platform)' == '.NET 4.5' "> <DefineConstants Condition="'$(DefineConstants)'==''"> TARGETTING_FX_4_5 </DefineConstants> <DefineConstants Condition="'$(DefineConstants)'!='' and '$(DefineConstants)'!='TARGETTING_FX_4_5'"> $(DefineConstants);TARGETTING_FX_4_5 </DefineConstants> <PlatformTarget Condition="'$(PlatformTarget)'!=''"/> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> </PropertyGroup> <!-- Import the standard C# targets --> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- Add .NET 4.5 as an available platform --> <PropertyGroup> <AvailablePlatforms>$(AvailablePlatforms),.NET 4.5</AvailablePlatforms> </PropertyGroup> </Project>
프로젝트를 언로드하십시오 (오른쪽 클릭-> 언로드).
프로젝트 파일을 편집하십시오 (마우스 오른쪽 버튼 클릭-> * .csproj 편집).
프로젝트 파일에서 다음을 변경하십시오.
ㅏ.
Microsoft.CSharp.targets
4 단계에서 작성된 대상 파일로 기본값 을 바꾸십시오.<!-- Old Import Entry --> <!-- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> --> <!-- New Import Entry --> <Import Project="Compile_4_5_CSharp.targets" />
비. 기본 플랫폼을
.NET 4.5
<!-- Old default platform entry --> <!-- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> --> <!-- New default platform entry --> <Platform Condition=" '$(Platform)' == '' ">.NET 4.5</Platform>
씨.
AnyCPU
프로젝트 속성에 지정된 다른 프레임 워크를 타겟팅 할 수 있도록 플랫폼을 추가하십시오 .<ItemGroup>
파일 의 첫 번째 태그 바로 앞에 추가해야 합니다.<PropertyGroup Condition="'$(Platform)' == 'AnyCPU'"> <PlatformTarget>AnyCPU</PlatformTarget> </PropertyGroup> . . . <ItemGroup> . . .
변경 사항을 저장하고
*.csproj
파일을 닫으십시오 .프로젝트를 다시로드하십시오 (오른쪽 클릭-> 프로젝트 다시로드).
In the configuration manager (Build -> Configuration Manager) make sure the ".NET 4.5" platform is selected for your project.
Still in the configuration manager, create a new solution platform for ".NET 4.5" (you can base it off "Any CPU") and make sure ".NET 4.5" is selected for the solution.
Build your project and check for errors.
Assuming the build completed you can verify that you are indeed targeting 4.5 by adding a reference to a 4.5 specific class to your source code:
using System; using System.Text; namespace testing { using net45check = System.Reflection.ReflectionContext; }
When you compile using the ".NET 4.5" platform the build should succeed. When you compile under the "Any CPU" platform you should get a compiler error:
Error 6: The type or namespace name 'ReflectionContext' does not exist in the namespace 'System.Reflection' (are you missing an assembly reference?)
FYI, if you want to create an Installer package in VS2010, unfortunately it only targets .NET 4. To work around this, you have to add NET 4.5 as a launch condition.
Add the following in to the Launch Conditions of the installer (Right click, View, Launch Conditions).
In "Search Target Machine", right click and select "Add Registry Search".
Property: REGISTRYVALUE1
RegKey: Software\Microsoft\NET Framework Setup\NDP\v4\Full
Root: vsdrrHKLM
Value: Release
Add new "Launch Condition":
Condition: REGISTRYVALUE1>="#378389"
InstallUrl: http://www.microsoft.com/en-gb/download/details.aspx?id=30653
Message: Setup requires .NET Framework 4.5 to be installed.
Where:
378389 = .NET Framework 4.5
378675 = .NET Framework 4.5.1 installed with Windows 8.1
378758 = .NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2
379893 = .NET Framework 4.5.2
Launch condition reference: http://msdn.microsoft.com/en-us/library/vstudio/xxyh2e6a(v=vs.100).aspx
I have been struggling with VS2010/DNFW 4.5 integration and have finally got this working. Starting in VS 2008, a cache of assemblies was introduced that is used by Visual Studio called the "Referenced Assemblies". This file cache for VS 2010 is located at \Reference Assemblies\Microsoft\Framework.NetFramework\v4.0. Visual Studio loads framework assemblies from this location instead of from the framework installation directory. When Microsoft says that VS 2010 does not support DNFW 4.5 what they mean is that this directory does not get updated when DNFW 4.5 is installed. Once you have replace the files in this location with the updated DNFW 4.5 files, you will find that VS 2010 will happily function with DNFW 4.5.
From another search. Worked for me!
"You can use Visual Studio 2010 and it does support it, provided your OS supports .NET 4.5.
Right click on your solution to add a reference (as you do). When the dialog box shows, select browse, then navigate to the following folder:
C:\Program Files(x86)\Reference Assemblies\Microsoft\Framework\.Net Framework\4.5
You will find it there."
참고URL : https://stackoverflow.com/questions/12390175/targeting-net-framework-4-5-via-visual-studio-2010
'Programming' 카테고리의 다른 글
Websockets 클라이언트 API의 HTTP 헤더 (0) | 2020.05.29 |
---|---|
파이썬 사전은 해시 테이블의 예입니까? (0) | 2020.05.29 |
SQL Server에서 사용자와 로그인의 차이점 (0) | 2020.05.29 |
다른 보존 정책이 내 주석에 어떤 영향을 줍니까? (0) | 2020.05.29 |
일반 유형 또는 메소드 'System.Nullable'에서 매개 변수 T로 사용하려면 'string'유형은 널 입력 불가능 유형이어야합니다. (0) | 2020.05.29 |