升级到 .NET 4.5 后 MSBuild 部署失败 [英] MSBuild deploy failing after upgrade to .NET 4.5

查看:36
本文介绍了升级到 .NET 4.5 后 MSBuild 部署失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将 VS 2010 和 .NET 4 应用程序升级到了 VS 2012 和 .NET 4.5.我们有一个构建脚本来在测试服务器上部署应用程序.我们有两个盒子 - 一个是带有 VS 2012(全新安装)的 Windows 8,另一个是带有 VS 2010 和 VS 2012(新安装)的 Windows 7.

We recently upgraded our VS 2010 and .NET 4 application to VS 2012 and .NET 4.5. We have a build script to deploy the application on the test server. We have two boxes - one is Windows 8 with VS 2012 (fresh install) and other is Windows 7 with VS 2010 and VS 2012 (installed newly).

从 Windows 8 运行构建脚本时,构建脚本运行良好并将应用程序部署到测试服务器.但是当从 Windows 7 box 部署应用程序时,我收到以下错误:

When running the build script from Windows 8 box build script is working well and deploys the application to test server. But when deploying the application from Windows 7 box I get the following error:

C:AchinthBuildWorkuildqa1sb.proj"(DeployAll 目标)(1) ->C:AchinthBuildWorkAppApp.csproj"(ResolveReferences;MsDeployPublish 目标)(2) ->(MSDeployPublish target) -> C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): 错误:Web 部署任务失败.((8/19/2012 6:23:41 PM) 在远程计算机上处​​理请求时出错.) [C:AchinthBuildWorkAppApp.csproj]C:​​Program文件 (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5):错误: [C:AchinthBuildWorkAppApp.csproj]C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): 错误 : (8/19/2012 6:23:41 PM) An在远程计算机上处​​理请求时出错. [C:AchinthBuildWorkAppApp.csproj]C:​​Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): 错误:应用程序 po您尝试使用的 ol 的managedRuntimeVersion"属性设置为v4.0".此应用程序需要v4.5".[C:AchinthBuildWorkAppApp.csproj]

"C:AchinthBuildWorkuildqa1sb.proj" (DeployAll target) (1) ->"C:AchinthBuildWorkAppApp.csproj" (ResolveReferences;MsDeployPublish target) (2) ->(MSDeployPublish target) -> C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): error : Web deployment task failed.((8/19/2012 6:23:41 PM) An error occurred when the request was processed on the remote computer.) [C:AchinthBuildWorkAppApp.csproj]C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): error : [C:AchinthBuildWorkAppApp.csproj]C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): error : (8/19/2012 6:23:41 PM) An error occurred when the request was processed on the remote computer. [C:AchinthBuildWorkAppApp.csproj]C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.targets(3847,5): error : The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v4.0'. This application requires 'v4.5'. [C:AchinthBuildWorkAppApp.csproj]

查看错误,似乎 MSBuild 正在使用 VS 2010 目标而不是 VS 2012,这会导致错误.由于 Windows 8 box 没有 VS 2010,因此它正确使用了 VS 2012 目标.

Looking at the error it looks like that MSBuild is using VS 2010 targets instead of VS 2012, which is causing the error. Since Windows 8 box does not have VS 2010 it is using VS 2012 targets correctly.

有人可以提供有关如何使 MSBuild 选择正确版本的指示吗?

Can some one please provide pointers on how to make MSBuild to pick the right version?

推荐答案

在这种情况下,您需要指定 MSBuild 属性 VisualStudioVersion=11.0.我刚刚在 http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx,为了您的方便,我也将其粘贴在下面.

In this case you will need to specify the MSBuild property VisualStudioVersion=11.0. I just blogged about this at http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx, I've pasted it below as well for your convenience.

Visual Studio 2012 最受欢迎的功能之一是能够在 VS 2012 和 VS 2010(需要 VS 2010 SP1)中打开项目.如果您还没有听说我们确实实现了该功能.您可能想知道我们是如何做到这一点的,以及这会对您产生什么影响.

One of the most requested features of Visual Studio 2012 was the ability to open projects in both VS 2012 as well as VS 2010 (requires VS 2010 SP1). In case you haven’t heard we did implement that feature. You may be wondering how we were able to do this and how this may impact you.

如果您为在 VS2010 中创建的 Web 项目打开 .csproj/.vbproj,您将看到以下导入语句.

If you open the .csproj/.vbproj for a Web Project created in VS2010 you will see the following import statement.

<Import Project="$(MSBuildExtensionsPath32)MicrosoftVisualStudio
                  v10.0WebApplicationsMicrosoft.WebApplication.targets" />

当您在 VS 2012 中打开此项目时,对您的项目文件进行了一些更改,以确保它可以在 VS 2010 SP1 和 VS 2012 中打开.第一次加载时对项目所做的更改之一在 VS 2012 中是添加以下内容来替换该导入语句.

When you open this project in VS 2012 there are a few changes made to your project file to ensure that it can be opened in both VS 2010 SP1 and VS 2012. One of the changes made to the project when it is first loaded in VS 2012 is to add the following to replace that import statement.

<PropertyGroup>
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">
    $(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)WebApplicationsMicrosoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

我们删除了硬编码的 10.0,而是使用了属性 VisualStudioVersion.在 Visual Studio 2012 中构建时,此值将始终为 11.0,但对于 VS 2010,它不存在.这就是我们将其默认为 10.0 以上的原因.在某些情况下,从命令行构建需要显式设置此属性.在我们到达那里之前,让我解释一下这个属性是如何设置的(按这个顺序)

We removed the hard-coded 10.0 and instead used the property VisualStudioVersion. When building in Visual Studio 2012 this value will always be 11.0, but for VS 2010 it doesn’t exist. That is why we defaulted it to 10.0 above. There are some scenarios where building from the command line will require to set this property explicitly. Before we get there let me explain how this property gets set (in this order)

  1. 如果 VisualStudioVersion 定义为环境变量/全局 MSBuild 属性,则使用该属性.
    • 这是 VS 和 VS 开发人员命令提示符设置此值的方式
  • 为了简化此语句,.sln 文件将通过将 VisualStudioVersion 指定为创建 .sln 文件的 VS 版本的值来构建.
  • 10.0(如果安装了 VS 2010)
  • 已安装最高版本的子工具集版本

对于#2,当您构建 .sln 文件时,VisualStudioVersion 的值将是 .sln 文件中的格式版本的 –1.这里要注意的重要一点是,如果您构建 .sln 文件,它将使用与创建 .sln 文件的 VS 版本相对应的 VisualStudioVersion 值进行构建.因此,如果您在 VS2012 中创建一个 .sln 文件并且您始终构建该 .sln 文件,则 VisualStudioVersion 的值将为 11.0.在许多情况下,如果您构建 .sln 文件,您就很好.

For #2 when you are building a .sln file the value of VisualStudioVersion will be –1 of the Format Version found in the .sln file. The important thing to note here is that if you build a .sln file it will build with the value of VisualStudioVersion corresponding to the version of VS which created the .sln file. So if you create a .sln file in VS2012 and you always build that .sln file the value for VisualStudioVersion will be 11.0. In many cases if you build the .sln file you are good.

如果您正在构建 .csproj/.vbproj 文件而无需通过 .sln 文件?如果您从命令行(而不是开发人员提示)构建 Web 项目,则使用的 VisualStudioVersion 的值将为 10.0.这是我上面显示的属性的人工制品.在这种情况下,您应该将其作为 MSBuild 属性传入.例如

If you are building .csproj/.vbproj files w/o going through a .sln file? If you build a web project from the command line (not the developer prompt) then the value for VisualStudioVersion used will be 10.0. That is an artifact of the properties which I showed above. In this case you should pass this in as an MSBuild property. For example

msbuild.exe MyAwesomeWeb.csproj /p:VisualStudioVersion=11.0

在这种情况下,我明确地传入了属性.这将始终覆盖任何其他机制来确定 VisualStudioVersion 的值.如果在构建脚本中使用 MSBuild 任务,则可以在 Properties 属性或 AdditionalProperties 属性中指定该属性.请参阅我之前关于 Properties 和 AdditionalProperties 之间区别的博文.

In this case I’m passing in the property explicitly. This will always override any other mechanism to determine the value for VisualStudioVersion. If you are using the MSBuild task in a build script, then you can specify the property either in the Properties attribute or the AdditionalProperties attribute. See my previous blog post on the difference between Properties and AdditionalProperties.

如果您在构建/发布时遇到任何有趣的行为,并且您注意到正在导入错误的 .targets 文件,那么您可能需要指定此属性.

If you encounter any funny behavior when building/publishing and you notice that the wrong .targets files are being imported then you may need to specify this property.

这篇关于升级到 .NET 4.5 后 MSBuild 部署失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆