msbuild - .Net Core MS 构建包创建生命周期
问题描述
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”文件中看不到!
解决方案
我发现在 .Net Core 中复制额外文件的解决方案取自本文档
<ItemGroup>
<DotnetPublishFiles Include="$(MSBuildProjectDirectory)\..\..somepath..\Extra.dll;....dll" >
<DestinationRelativePath>bin\x86\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</DotnetPublishFiles>
</ItemGroup>
推荐阅读
- c++ - 调试c++时如何在vscode中添加额外的源目录
- javascript - 在 Javascript 中重新格式化字符串
- laravel - 为什么获取数据在刀片中不起作用但在 dd 时起作用?
- angular - 改变了角材料的进口
- if-statement - 我想在序列号中排除空白
- python - 如何使用 spaCy 检查文档中是否存在令牌?
- typescript - 如何使用带有 TS 的玩笑来模拟 EventSource(尝试了大部分模拟策略)
- app.yaml - 如何为静态目录索引设置 app.yaml
- python - 如何在python中获得嵌套的href?
- authentication - 找不到 Watson Assistant 登录信息