msbuild - MSBuild 知名项元数据和 NuGet 包
问题描述
我正在尝试将自定义文件添加到特定的 NuGet 包(基本上我需要 NuGet 包中包含的所有输出文件,因为它用作 Chocolatey 的工具)。
经过一番搜索,我发现了这个潜在的修复:
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetToolsPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="GetToolsPackageFiles">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)\**\*.dll" />
<BuildOutputInPackage Include="$(OutputPath)\**\*.exe" />
</ItemGroup>
</Target>
不幸的是,这不适用于子目录,所以我尝试了这个:
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetToolsPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="GetToolsPackageFiles">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)\**\*.dll">
<TargetPath>$([MSBuild]::MakeRelative('$(OutputPath)', %(FullPath)))</TargetPath>
</BuildOutputInPackage>
<BuildOutputInPackage Include="$(OutputPath)\**\*.exe">
<TargetPath>$([MSBuild]::MakeRelative('$(OutputPath)', %(FullPath)))</TargetPath>
</BuildOutputInPackage>
</ItemGroup>
</Target>
根据文档,我应该能够使用 %(FullPath),但是我收到了这个错误:
error MSB4184: The expression "[MSBuild]::MakeRelative(C:\Sour
ce\RepositoryCleaner\output\Release\RepositoryCleaner\netcoreapp3.1\, '')" cannot be evaluated. Parameter "path" cannot have zero length.
[C:\Source\RepositoryCleaner\src\RepositoryCleaner\RepositoryCleaner.csproj]
知道为什么众所周知的项目在这种情况下似乎不起作用吗?
解决方案
通过在目标之外指定项目组然后使用它来解决问题。
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetToolsPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<ToolDllFiles Include="$(OutputPath)\**\*.dll" />
<ToolExeFiles Include="$(OutputPath)\**\*.exe" />
</ItemGroup>
<Target Name="GetToolsPackageFiles">
<ItemGroup>
<BuildOutputInPackage Include="@(ToolDllFiles)">
<TargetPath>$([MSBuild]::MakeRelative('$(OutputPath)', %(ToolDllFiles.FullPath)))</TargetPath>
</BuildOutputInPackage>
<BuildOutputInPackage Include="@(ToolExeFiles)">
<TargetPath>$([MSBuild]::MakeRelative('$(OutputPath)', %(ToolExeFiles.FullPath)))</TargetPath>
</BuildOutputInPackage>
</ItemGroup>
</Target>
推荐阅读
- terminology - “逐字节”的术语,是什么意思?
- javascript - In HTML, is it possible to partially format or
- python - 在 Python 中使用 readline() 读取文件的正确条件
- python - 获取具有最大数字元素的元组,如果出现平局,则随机选择一个平局元组
- ios - Swift - 日期更改时区
- webpack - Webpack 4 ignores UglifyJsPlugin
- excel - Excel VBA Single VS Double Data Type
- javascript - firebase 事务和 if-then-else 行为
- java - 如何改进我对 Android SharedPreference 的使用?
- android - 无法加载类'kotlin.reflect.KDeclarationContainer'.android studio 3.1.4