【问题标题】:.Net Core MS Build Package Creation Lifecycle.Net Core MS 构建包创建生命周期
【发布时间】:2019-02-19 05:23:49
【问题描述】:

MSBuild 相当强大和重要的工具,但有时配置它就像制造宇宙飞船或飞往火星一样困难。下一个问题的答案可以帮助它变得更有用和对开发人员友好: - MSBuild 如何创建一个包(zip)? - 它是使用一些临时文件夹还是直接来自构建输出? - 为什么输出文件夹内容与包内容不同 - 可以使用哪些事件来添加一些自定义逻辑?

这个问题的答案可以帮助我完成下一个长话短说: 我正在使用 .Net Core 解决方案,该解决方案依赖于其他一些解决方案 DLL 文件(未直接引用,但需要位于解决方案文件夹中)。在构建后事件 CL 上,添加了作为入口点“\TaskEP”的选项,这是下一个管道的起点:

<PropertyGroup>
<PipelineCopyAllFilesToOneFolderForMsdeployDependsOn>
  TaskEP;
  Task2;
  Task3;
  $(PipelineCopyAllFilesToOneFolderForMsdeployDependsOn);
</PipelineCopyAllFilesToOneFolderForMsdeployDependsOn>
<RunPostBuildEvent>Always</RunPostBuildEvent>

任务主要是为了将额外的 DLL 添加到包中,一般看起来像:

<Target Name="TaskEP" Condition="$(SomeConditions) == 'True'">
    <Message Importance="high" Text="TaskEP: Copying some files..." />
    <ItemGroup>
      <ItemsName Include="$(MSBuildProjectDirectory)\..\..somepath..\Extra.dll;....dll" />
      <FilesForPackagingFromProject Include="%(ItemsName.Identity)">
        <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>

基本上,对我来说,这条指令是向 MSBuild 添加“Extra.dll”到输出包。
Pubxml 很常见:

 <PropertyGroup>
<WebPublishMethod>Package</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<_PackagePathShortened Condition="'$(_PackagePathShortened)' == ''">SuperWebSite</_PackagePathShortened>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PackageLocation>..\..\..\..\BIN\WEB\Release\Publish\Super.WebApplication.zip</PackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<TargetFramework>netcoreapp2.1</TargetFramework> ....

还有一条指令,将包中的long long 路径替换为Short 并定义一条:

<Target Name="AddReplaceRuleForAppPath" BeforeTargets="BeforePublish">
<Message Text="Adding replace rules for application path '$(PublishIntermediateOutputPath)' replace with '$(_PackagePathShortened)'" Importance="high" />
<EscapeTextForRegularExpressions Text="$(PublishIntermediateOutputPath)">
  <Output PropertyName="_PackagePathRegex" TaskParameter="Result" />
</EscapeTextForRegularExpressions>
<!-- Add a replace rule for VSMSDeploy resp. MSdeploy to update the path -->
<ItemGroup>
  <MsDeployReplaceRules Include="replaceFullPath">
    <Match>$(_PackagePathRegex)</Match>
    <Replace>$(_PackagePathShortened)</Replace>
  </MsDeployReplaceRules>
</ItemGroup>

我还在 .pubxml 文件中复制了相同的“复制”任务,使用不同的事件“AfterBuild”、“BeforePublish”,但似乎所有这些都被忽略了。我可以在构建输出目录和所有发布信息消息中看到“额外”DLL 文件,但在最终的“Super.WebApplication.zip”文件中看不到!

【问题讨论】:

标签: msbuild .net-core msdeploy pubxml


【解决方案1】:

我找到的在.Net Core中复制额外文件的解决方案取自documentation

<ItemGroup>
    <DotnetPublishFiles Include="$(MSBuildProjectDirectory)\..\..somepath..\Extra.dll;....dll" >
      <DestinationRelativePath>bin\x86\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </DotnetPublishFiles>
  </ItemGroup>

【讨论】:

    猜你喜欢
    • 2022-06-14
    • 1970-01-01
    • 2013-04-06
    • 2021-08-01
    • 2018-12-12
    • 2022-07-08
    • 2010-09-07
    • 2019-09-28
    • 2016-07-31
    相关资源
    最近更新 更多