[英]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包中包含源文件的方法,但是似乎不再受支持。
現在有適當的方法嗎?
謝謝!
您可以使用contentFiles
分區到.nuspec
文件中。 這是一個完整的例子
<?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
元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.