如何创建共享源文件的 nuget 包?
How can I create a nuget package that shares source files?
我想弄清楚是否有一种方法可以创建一个 nuget 包,该包可用于共享依赖项,而这些依赖项确实是开发关注的问题,而不是消费者关注的问题。我们的团队有一组 Check
(或 Guard
或 Ensure
等)我们在所有项目中使用的方法。现在我们只需将 csharp 文件从一个存储库复制到另一个存储库,并通过手动修改 csproj 以包括:
从该存储库中的所有项目引用它们
<Compile Include="..\Shared\Check.cs" Link="Properties\Check.cs" />
理想情况下,我想创建一个 nuget 包,以便我们可以对这些 类 进行版本控制,但我不希望 nuget 包显示为我们编写的每个项目的依赖项。曾经有一种方法可以在 nuget 包中包含源文件,但现在似乎不再支持了。
现在有合适的方法吗?
谢谢!
您可以在 .nuspec
文件中使用 contentFiles
部分。这是一个完整的例子
<?xml version="1.0"?>
<package>
<metadata minClientVersion="3.3.0">
<id>ContentFilesExample</id>
<version>1.0.0</version>
<authors>nuget</authors>
<!-- The NuGet team authored this package -->
<owners>nuget</owners>
<!-- The NuGet team owns this package -->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A content v2 example package.</description>
<tags>contentv2 contentFiles</tags>
<!-- Build actions for items in the contentFiles folder -->
<contentFiles>
<!-- Include Assets as Content -->
<files include="**/images/*.*" buildAction="EmbeddedResource" />
</contentFiles>
</metadata>
</package>
对于 NuGet 2.x 及更早版本,以及使用 packages.config 的项目,files
元素还用于在安装包时包含不可变内容文件。对于 NuGet 3.3+ 和使用 project.json pr PackageReference 的项目,将改为使用 contentFiles
元素。
我想弄清楚是否有一种方法可以创建一个 nuget 包,该包可用于共享依赖项,而这些依赖项确实是开发关注的问题,而不是消费者关注的问题。我们的团队有一组 Check
(或 Guard
或 Ensure
等)我们在所有项目中使用的方法。现在我们只需将 csharp 文件从一个存储库复制到另一个存储库,并通过手动修改 csproj 以包括:
<Compile Include="..\Shared\Check.cs" Link="Properties\Check.cs" />
理想情况下,我想创建一个 nuget 包,以便我们可以对这些 类 进行版本控制,但我不希望 nuget 包显示为我们编写的每个项目的依赖项。曾经有一种方法可以在 nuget 包中包含源文件,但现在似乎不再支持了。
现在有合适的方法吗?
谢谢!
您可以在 .nuspec
文件中使用 contentFiles
部分。这是一个完整的例子
<?xml version="1.0"?>
<package>
<metadata minClientVersion="3.3.0">
<id>ContentFilesExample</id>
<version>1.0.0</version>
<authors>nuget</authors>
<!-- The NuGet team authored this package -->
<owners>nuget</owners>
<!-- The NuGet team owns this package -->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A content v2 example package.</description>
<tags>contentv2 contentFiles</tags>
<!-- Build actions for items in the contentFiles folder -->
<contentFiles>
<!-- Include Assets as Content -->
<files include="**/images/*.*" buildAction="EmbeddedResource" />
</contentFiles>
</metadata>
</package>
对于 NuGet 2.x 及更早版本,以及使用 packages.config 的项目,files
元素还用于在安装包时包含不可变内容文件。对于 NuGet 3.3+ 和使用 project.json pr PackageReference 的项目,将改为使用 contentFiles
元素。