Gol*_*ius 165 visual-studio-2010 visual-studio .net-4.5
今天我在我的机器上安装了.NET Framework 4.5,希望能够在Visual Studio 2010中使用它,因为它只是一个小的更新,不应该给Visual Studio 2010带来问题.不幸的是我不是,甚至手动删除某些4.0并添加相应的4.5程序集导致原始4.0程序集仍在项目中引用.
是否可以从Visual Studio 2010中定位4.5版,如果是,如何?我真的很想用丝带......
小智 192
Visual Studio 2010之前的每个Visual Studio版本都与特定的.NET框架相关联.(VS2008是.NET 3.5,VS2005是.NET 2.0,VS2003是.NET1.1)Visual Studio 2010及更高版本允许定位先前的框架版本,但不能用于将来的版本.您必须使用Visual Studio 2012才能使用.NET 4.5.
小智 67
有一些相当有限的场景,我可以想到这将有用,但我们假设您无法获得资金购买VS2012或其他类似的东西.如果是这种情况并且您拥有Windows 7+和VS 2010,那么您可以使用我放在一起的以下hack似乎可行(但我尚未使用此方法完全部署应用程序).
备份你的项目文件!
下载并安装包含.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>
Run Code Online (Sandbox Code Playgroud)卸载您的项目(右键单击 - >卸载).
编辑项目文件(右键单击 - >编辑*.csproj).
在项目文件中进行以下更改:
一个.将默认值替换为Microsoft.CSharp.targets在步骤4中创建的目标文件
<!-- Old Import Entry -->
<!-- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -->
<!-- New Import Entry -->
<Import Project="Compile_4_5_CSharp.targets" />
Run Code Online (Sandbox Code Playgroud)
湾 将默认平台更改为.NET 4.5
<!-- Old default platform entry -->
<!-- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> -->
<!-- New default platform entry -->
<Platform Condition=" '$(Platform)' == '' ">.NET 4.5</Platform>
Run Code Online (Sandbox Code Playgroud)
C.添加AnyCPU平台以允许定位项目属性中指定的其他框架.这应该<ItemGroup>在文件中的第一个标记之前添加
<PropertyGroup Condition="'$(Platform)' == 'AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
.
.
.
<ItemGroup>
.
.
.
Run Code Online (Sandbox Code Playgroud)保存更改并关闭*.csproj文件.
重新加载项目(右键单击 - >重新加载项目).
在配置管理器(Build - > Configuration Manager)中,确保为项目选择了".NET 4.5"平台.
仍然在配置管理器中,为".NET 4.5"创建一个新的解决方案平台(您可以将其基于"任何CPU"),并确保为该解决方案选择".NET 4.5".
构建项目并检查错误.
假设构建完成,您可以通过在源代码中添加对4.5特定类的引用来验证您确实以4.5为目标:
using System;
using System.Text;
namespace testing
{
using net45check = System.Reflection.ReflectionContext;
}
Run Code Online (Sandbox Code Playgroud)使用".NET 4.5"平台进行编译时,构建应该会成功.当您在"任何CPU"平台下编译时,您应该收到编译器错误:
Error 6: The type or namespace name 'ReflectionContext' does not exist in
the namespace 'System.Reflection' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)仅供参考,如果你想在VS2010中创建一个安装程序包,不幸的是它只针对.NET 4.要解决这个问题,你必须添加NET 4.5作为启动条件.
将以下内容添加到安装程序的启动条件中(右键单击,查看,启动条件).
在"搜索目标计算机"中,右键单击并选择"添加注册表搜索".
Property: REGISTRYVALUE1
RegKey: Software\Microsoft\NET Framework Setup\NDP\v4\Full
Root: vsdrrHKLM
Value: Release
Run Code Online (Sandbox Code Playgroud)
添加新的"启动条件":
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.
Run Code Online (Sandbox Code Playgroud)
哪里:
378389 = .NET Framework 4.5
378675 =随Windows 8.1一起安装的.NET Framework 4.5.1
378758 =在Windows 8,Windows 7 SP1或Windows Vista SP2上安装的.NET Framework 4.5.1
379893 = .NET Framework 4.5.2
启动条件参考:http://msdn.microsoft.com/en-us/library/vstudio/xxyh2e6a(v = vs.100).aspx
| 归档时间: |
|
| 查看次数: |
204853 次 |
| 最近记录: |