如何避免将 .exe 文件复制到 nupkg 的 lib 目录中

How to avoid copying .exe file into nupkg's lib directory

我会自动将我的 c# 项目的输出(.exe 文件)打包到某个 nuget 包中。目前我有项目级的 nuget 包(这意味着我可以在项目相关的 packages.config 文件中安装这个包)。 此包的结构:

/lib/net40/myexe.exe
/lib/net40/myexe.dll
/myexe.nuspec

..等等。

我会将其转换为解决方案级包,这样我就可以将它安装到其他解决方案中,但我不需要将我的 myexe.dll 添加到引用中。所以根据 nuget 文档 "A package is considered a solution-level package if it does not contain any files in its lib, content, or build directories."

我在我的 .nuspec 文件中声明了文件部分:

<files>
  <file src="..\build$id$.exe" target="bin\" />
</files>

但我仍然有以下 nupkg 结构:

/lib/net40/myexe.exe
/lib/net40/myexe.dll
/bin/myexe.exe
/bin/myexe.dll
/myexe.nuspec

如何避免我的包中出现 /lib/ 目录?

解决方案是设置工具标志:

nuget pack <PackageProject.csproj> -outputDirectory <OutputDirectory> -BasePath <OutputDirectory> -Tool