问题
First let me add some context to error I get, I have installed .NET 4.5.1 Preview and first thing that I noticed in VS 2012 is that .NET 4.5.1 isn't listed in available frameworks. I'm not sure if this is correct behavior because this is just an upgrade to 4.5 so I guess VS 2012 should list it.
Further more when I installed a VS 2013 Preview, upgraded my project to .NET 4.5.1 and opened the solution in VS 2012 new .NET version reappeared so I'm not sure if this is a bug in VS 2012 or not ? Ok so now I have .NET 4.5.1 in VS 2012 and when I try to build a project I get the following error
Error 3 The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Build.Tasks.v4.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Build.Tasks.v4.0.dll' or one of its dependencies. The system cannot find the file specified. D:\Projects\MyProject\Master\Source\.nuget\nuget.targets 71 9 MyProject.Core.Modules
NuGet.targets reported line
<SetEnvironmentVariable EnvKey="VisualStudioVersion"
EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)'
!= '' AND '$(OS)' == 'Windows_NT' " />
It seems to me that for some reason VS 2012 can't resolve the paths or assemblies so I'm not sure if I should fix something in the NuGet.targets or is it a Visual Studio thing, any ideas ?
Thanks
回答1:
Building .NET Framework 4.5.1 applications is supported in Visual Studio 2012. You need to either install Visual Studio 2013 Preview or Windows SDK for Windows 8.1 Preview to get the .NET Framework 4.5.1 Preview Targeting pack on the same machine as Visual Studio 2012 to build applications with .NET Framework 4.5.1 preview.
Thanks
Nithya [MSFT]
回答2:
i solved changing the ToolsVersion in .csproj file.
From
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
To
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
回答3:
To fix this I had to upgrade the NuGet.targets and change the following two lines
From
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
To
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
Also it would be nice to get some answers related to .NET 4.5.1 Preview not showing up in VS 2012 up until I installed the VS 2013.
Nice chat with myself.
回答4:
Here's a blog post that Microsoft wrote on this topic.
Building apps with the .NET Framework 4.5.1 Preview in Visual Studio 2012
来源:https://stackoverflow.com/questions/17609184/net-4-5-1-preview-support-in-visual-studio-2012