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

时间:2017-12-05 12:47:41

标签: azure visual-studio-2015 msbuild tfsbuild azure-pipelines

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

带有.Net framework 4.5.1的项目使用带有以下参数的msbuild任务构建p,并且它正确地将代码发布到azure。一切都很好!!

enter image description here

.Net框架4.6.1项目使用msbuild任务正确构建,参数如下。

enter image description here

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

enter image description here

请帮忙,真的很奇怪。我在两个web api解决方案之间看到的唯一区别是 .Net框架版本。

2 个答案:

答案 0 :(得分:0)

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

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

尝试在MSBuild参数中强制使用“PublishProfileRootFolder”参数。详情请参阅此问题:MsBuild not finding publish profile

答案 1 :(得分:0)

使用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> 

您可以找到有关实施@ page 168

的更多详细信息