我正在尝试使用内置的 nuget 包构建在 Visual Studio 中创建一个 nupkg,并将我的项目中的构建目录包含在 nupkg 中。看起来这应该是一项相当简单的任务,但我无法让它工作。从我的谷歌搜索中,将其中任何一个添加到我的 csproj 文件应该可以工作,但两者都在 nupkg 中创建一个空的“build”目录:
<ItemGroup>
<None Include="build\**">
<Pack>true</Pack>
<PackagePath>build\</PackagePath>
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
使用
nuget pack
在我的 nuspec 中使用以下内容创建包确实有效: <files>
<!-- Include everything in \build -->
<file src="build\**" target="build" />
</files>
最佳答案
Include build directory in nuget package using visual studio pack
根据文档Including content in a package ,您应该使用属性
<Pack>true</Pack>
和 <PackagePath>build\</PackagePath>
:If you want to copy all your content to only a specific root folder(s) (instead of content and contentFiles both), you can use the MSBuild property ContentTargetFolders, which defaults to "content;contentFiles" but can be set to any other folder names.
PackagePath
can be a semicolon-delimited set of target paths. Specifying an empty package path would add the file to the root of the package.
因此,您可以像下面这样更改您的 ItemGroup:
<ItemGroup>
<None Include="build\**" Pack="True" PackagePath="build\" />
</ItemGroup>
更新:
I believe this is the same as what I added but in a different XML structure and without the Pack attribute
Pack
属性是关键。它适用于您的 XML 结构和 Pack 属性。您应该确保您在 中拥有这些文件。构建 中的文件夹您的项目文件夹 :在下面检查我的测试演示:
更新 2:
啊!您正在使用
.net framework
项目!!这就是这个问题的原因。此方法用于.net standard
和 .net core
项目默认情况下,它不适用于 .net framework
.要解决此问题,您必须使用 .nupsec
文件,就像你在问题中发帖一样。如果您仍想在 nuget 包中包含构建目录 使用 Visual Studio 包 ,您需要将项目类型更改为 SDK 类型:
查询 this document了解更多详情。
然后就可以使用我们之前讲过的方法了。
希望这可以帮助。
关于visual-studio - 使用 Visual Studio 包在 nuget 包中包含构建目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53281775/