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

查看:84
本文介绍了升级到.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盒中部署应用程序时,出现以下错误:

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:\ Achinth \ Build \ Work \ build \ qa1sb.proj"(DeployAll目标)(1)->"C:\ Achinth \ Build \ Work \ App \ App \ App.csproj"(ResolveReferences; MsDeployPublish目标) (2)->(MSDeployPublish目标)-> C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web \ Microsoft.Web.Publishing.targets(3847,5):错误:Web部署任务失败.(((8/19/2012 6:23:41 PM)在远程计算机上处​​理请求时发生错误.)[C:\ Achinth \ Build \ Work \ App \ App.csproj] C:\ Program文件(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web \ Microsoft.Web.Publishing.targets(3847,5):错误:\ r [C:\ Achinth \ Build \ Work \ App \ App.csproj] C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web \ Microsoft.Web.Publishing.targets(3847,5):错误:(8/19/2012 6:23:41 PM)在远程计算机上处​​理请求时发生错误.\ r [C:\ Achinth \ Build \ Work \ App \ App.csproj] C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web \ Microsoft.Web.Publishing.targets(3847,5):错误:应用程序po您尝试使用的所有语言都将"managedRuntimeVersion"属性设置为"v4.0".此应用程序需要"v4.5". [C:\ Achinth \ Build \ Work \ App \ App.csproj]

"C:\Achinth\Build\Work\build\qa1sb.proj" (DeployAll target) (1) ->"C:\Achinth\Build\Work\App\App.csproj" (ResolveReferences;MsDeployPublish target) (2) ->(MSDeployPublish target) -> C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.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:\Achinth\Build\Work\App\App.csproj]C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3847,5): error : \r [C:\Achinth\Build\Work\App\App.csproj]C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.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.\r [C:\Achinth\Build\Work\App\App.csproj]C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.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:\Achinth\Build\Work\App\App.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)\Microsoft\VisualStudio\
                  v10.0\WebApplications\Microsoft.WebApplication.targets" />

在VS 2012中打开此项目时,对项目文件进行了一些更改,以确保可以在VS 2010 SP1和VS 2012中将其打开.第一次加载时对项目进行的更改之一在VS 2012中,将添加以下内容以替换该import语句.

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)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.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开发人员命令提示符设置此值的方式
  1. If VisualStudioVersion is defined as an environment variable/global MSBuild property, that is used.
    • This is how VS and the VS developer command prompt set this value
  • 为简化此语句,将在将VisualStudioVersion指定为创建.sln文件的VS版本的值的情况下构建.sln文件.
  • 如果已安装VS 2010,则为10.0
  • 已安装版本最高的子工具集

对于#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属性中指定属性.请参阅我以前的博客文章,了解属性"和其他属性"之间的区别.

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天全站免登陆