VS 2013和MSBuild

问题描述:

我最近升级到了Visual Studio 2013,在使用MSBuild(API或带有命令行参数的可执行文件)进行外部构建时,这引起了背对背的问题

I've recently upgraded to Visual Studio 2013, which has caused back to back problems when building externally using MSBuild (API or Executable with command line args)

问题#1 使用MSBuild进行构建时,它不会生成我们的单元测试所需的Fake程序集,这会导致构建失败. Visual Studio中的一个简单构建会暂时修复此问题,直到需要生成新的假程序集为止.

Issue #1 When building with MSBuild it doesn't generate Fake assemblies which are required for our Unit Tests, this leads to build failures. A simple build in visual studio fixes this temporarily, until a new fake assembly needs to be generated.

问题2 在运行代码分析时,会抱怨以下问题:

Issue #2 When running code analysis this complains with the following:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(284,5): 
error MSB4127: The "CodeAnalysis" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\.\FxCopTask.dll". 

Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.CodeAnalysis' to type 'Microsoft.Build.Framework.ITask'.

我只在计算机上安装了Visual Studio 2013,显然,安装旧版本可以解决此问题,但这不是我可以做的. (VS 2013附带了自己的MSBuild 12.0,与以前的MSBuild位于不同的目录中.)

I only have Visual Studio 2013 installed on my machine, apparently installing an older version could fix the issue, but it's not something which I can do. (VS 2013 Ships with its own MSBuild 12.0 which is located in a different directory to the previous MSBuild).

我不确定为什么Visual Studio的行为与MSBuild有所不同,我只是像这样指向解决方案文件...

I'm unsure why Visual Studio is behaving any differently to MSBuild, i'm simply pointing to the solution file like so...

msbuild.exe "path\solution.sln" /property:Configuration=Debug

因此,Visual Studio 2013附带了一个新版本的MSBuild,即MSBuild 12.0.安装后,它将更改路径,以便默认使用新版本.

So, Visual Studio 2013 comes with a new version of MSBuild i.e. MSBuild 12.0. Once installed, it changes the path so that the new version is used by default.

好像您的解决方案是使用Visual Studio 2012编译的,您可以指定msbuild.exe的完整路径,例如

Looks like your solution compiles with visual studio 2012, you can either specify the full path to msbuild.exe such as

C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild"path \ solution.sln"/property:Configuration = Debug

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild "path\solution.sln" /property:Configuration=Debug

或在执行msbuild之前通过运行以下命令来设置Visual Studio 2012环境变量

or set the visual studio 2012 environment variables by running the following before executing msbuild

%VS110COMNTOOLS%" \ vsvars32.bat//VS2012环境变量

"%VS110COMNTOOLS%"\vsvars32.bat // VS2012 environment variables

编辑:使用MSbuild 12.0程序集"C:\ Program Files(x86)\ MSBuild \ 12.0 \ Bin \"解决了代码分析错误的问题.

Using MSbuild 12.0 assemblies "C:\Program Files (x86)\MSBuild\12.0\Bin\" fixes the issue with the code Analysis bug.