1

在 VS2017 中,我运行这个 pubxml 文件。

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Date>$([System.DateTime]::Now.ToString(yyyyMMdd))</Date>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Prod</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <Major>0</Major>
    <Minor>1</Minor>
    <Build>2</Build>
    <Publish>c:\</Publish>
    <publishUrl>$(Publish)</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>

  <Target Name="GetBuildUrl">
    <PropertyGroup>
      <In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs'))</In>
      <Pattern>^\s*\[assembly: AssemblyVersion\(\D*(\d+)\.(\d+)\.(\d+)</Pattern>
      <Major>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</Major>
      <Minor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[2].Value)</Minor>
      <Build>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[3].Value)</Build>
      <Publish>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), _ReleaseRoot.txt))\FlightmapReleases\Releases\Flightmap $(Major).$(Minor)\Prod\$(Date) ($(Major).$(Minor).$(Build))\</Publish>
      <publishUrl Condition=" '$(Publish)' != '' ">$(Publish)</publishUrl>
      <publishUrl Condition=" '$(Publish)' == '' and '$(LastUsedBuildConfiguration)'!='' ">$(LastUsedBuildConfiguration)</publishUrl>
    </PropertyGroup>
  </Target>

  <Target Name="BeforeBuild" DependsOnTargets="GetBuildUrl">
    <Message Importance="High" Text="|" />
    <Message Importance="High" Text=" =================================================================================================" />
    <Message Importance="High" Text="    BUILD INFO                                                                                    " />
    <Message Importance="High" Text="    Version [$(Major).$(Minor).$(Build)] found in [$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs] " />
    <Message Importance="High" Text="    Build will be saved to [$(publishUrl)]                                                        " />
    <Message Importance="High" Text=" =================================================================================================" />
    <Message Importance="High" Text="|" />
  </Target>
</Project>

因为发布位置不在项目根目录中,它会搜索文件“_ReleaseRoot.txt”并将包含文件夹设置为根目录。消息传递目标为所有属性提供正确的值,所以我认为这是可行的。

当我运行发布消息是这样的:

------ Build started: Project: Flightmap.Web, Configuration: Debug Any CPU ------   
|      
===================================================================
    BUILD INFO                                                                                    
    Version [5.4.0] found in [(correct project)\Properties\AssemblyInfo.cs]
    Build will be saved to [(correct location)\Prod\20170413 (5.4.0)\]
===================================================================

在我看来很好。然后开始构建,说

Connecting to c:\...

它的结尾并不令人惊讶

Publish failed. Target file:///c:/.

我怎样才能得到这个工作?

4

1 回答 1

0

我有类似的问题,它通过更改csproj文件解决:

来自(可能与您略有不同,例如 v4):

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

变成

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" Condition="true" />

这是最新版本的 VS2017 (15.82) 和 MSBuild 15 (2019)。

于 2019-03-25T03:59:08.037 回答