Msbuild 忽略 azure 发布配置文件设置 - Visual Studio 2015 - .Net 4.6.1

Msbuild ignores azure publish profile settings - Visual Studio 2015 - .Net 4.6.1

我的解决方案中有 2 个 Web API 项目。一个项目是4.5.1,另一个项目是4.6.1.

Project with .Net framework 4.5.1 使用具有以下参数的 msbuild 任务构建 p,并将代码正确发布到 azure。很好!!

使用 .Net Framework 4.6.1 的项目可以使用具有以下参数的 msbuild 任务正确构建。

使用上述参数构建时,创建的包未部署到 azure。请参阅下面的日志。

求助,真是奇怪。我在两个网络 api 解决方案之间看到的唯一区别是 .Net 框架版本。

首先建议您手动使用msbuild.exe命令进行发布。这将缩小是否与 TFS 端相关的问题。

还将构建代理上的 Azure SDK 更新到最新版本(Azure SDK for .NET 3.0)。

尝试在 MSBuild 参数中强制使用 "PublishProfileRootFolder" 参数。详情请参考这个问题:MsBuild not finding publish profile

使用 wpp 文件 xml 查看您的发布设置,这将在 msbuild 运行时生成发布配置文件。使用下面的 xml 片段创建 wpp 文件。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 

  <!--
  When using this file you must supply /p:PublishSettingsFile as a parameter and /p:DeployOnBuild=true
  -->  
  <PropertyGroup Condition=" Exists('$(PublishSettingsFile)')">
    <!-- These must be declared outside of a Target because they impact the Import Project flow -->
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <DeployTarget>WebPublish</DeployTarget>

    <PipelineDependsOn>
      GetPublishPropertiesFromPublishSettings;
      $(PipelineDependsOn);
    </PipelineDependsOn>
  </PropertyGroup>

  <Target Name="GetPublishPropertiesFromPublishSettings" BeforeTargets="Build" Condition=" Exists('$(PublishSettingsFile)')">
    <PropertyGroup>
      <_BaseQuery>/publishData/publishProfile[@publishMethod='MSDeploy'][1]/</_BaseQuery>
      <!-- This value is not in the .publishSettings file and needs to be specified, it can be overridden with a cmd line parameter -->
      <!-- If you are using the Remote Agent then specify this as RemoteAgent -->
      <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    </PropertyGroup>

    <ItemGroup>
      <_MSDeployXPath Include="WebPublishMethod">
        <Query>$(_BaseQuery)@publishMethod</Query>
      </_MSDeployXPath>

      <_MSDeployXPath Include="MSDeployServiceURL">
        <Query>$(_BaseQuery)@publishUrl</Query>
      </_MSDeployXPath>

      <_MSDeployXPath Include="SiteUrlToLaunchAfterPublish">
        <Query>$(_BaseQuery)@destinationAppUrl</Query>
      </_MSDeployXPath>

      <_MSDeployXPath Include="DeployIisAppPath">
        <Query>$(_BaseQuery)@msdeploySite</Query>
      </_MSDeployXPath>

      <_MSDeployXPath Include="UserName">
        <Query>$(_BaseQuery)@userName</Query>
      </_MSDeployXPath>

      <_MSDeployXPath Include="Password">
        <Query>$(_BaseQuery)@userPWD</Query>
      </_MSDeployXPath>
    </ItemGroup>

    <XmlPeek XmlInputPath="$(PublishSettingsFile)"
             Query="%(_MSDeployXPath.Query)"
             Condition=" Exists('$(PublishSettingsFile)')">
      <Output TaskParameter="Result" PropertyName="%(_MSDeployXPath.Identity)"/>
    </XmlPeek>
  </Target>
</Project>

使用以上 xml 代码片段创建一个 wpp 文件并将其放置在您的 csproj 所在的同一项目中,或者如果您将 wpp 放置在 csproj 文件夹之外以在多个项目中重复使用,那么您需要添加 /p:WebPublishPipelineCustomizeTargetFile=

msbuild.exe MyProject /p:WebPublishPipelineCustomizeTargetFile=<path-to.targets-file>  /p:VisualStudioVersion=11.0 /p:DeployOnBuild=true /p:PublishSettingsFile=<path-to-.publishsettings> 

您可以在@http://sedodream.com/2013/06/05/HowToPublishAVSWebProjectWithAPublishSettingsFile.aspx

中找到更多关于实现的细节