【问题标题】:MSBuild well-known item metadata and NuGet packMSBuild 知名项元数据和 NuGet 包
【发布时间】:2020-07-23 13:49:47
【问题描述】:

我正在尝试将自定义文件添加到特定的 NuGet 包(基本上我需要 NuGet 包中包含的所有输出文件,因为它用作 Chocolatey 的工具)。

经过一番搜索,我发现了这个潜在的解决方法:

  <PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetToolsPackageFiles</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>

  <Target Name="GetToolsPackageFiles">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutputPath)\**\*.dll" />
      <BuildOutputInPackage Include="$(OutputPath)\**\*.exe" />
    </ItemGroup>
  </Target>

不幸的是,这对于 sub 目录不能正常工作,所以我尝试了这个:

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

根据the docs,我应该可以使用 %(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]

知道为什么众所周知的项目在这种情况下似乎不起作用吗?

【问题讨论】:

标签: msbuild nuget


【解决方案1】:

通过在目标之外指定项目组然后改用它来解决问题。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多