[英]Is there a command to point nuget.exe to a specific NuGet.Config file?
[英]nuget.exe doesn't recognize any target framework in nuspec file
我有一個項目,可以通過在CSPROJ文件中設置以下選項直接在Visual Studio中生成NuGet包:
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
這將導致生成的程序包包括所有已標記為“復制到輸出目錄=不復制”的嵌入式資源文件。
可悲的是,Visual Studio的自動打包程序選擇始終將這些文件復制到NuGet程序包中。
為了解決這個問題,我一直在研究編輯.NUSPEC文件,並從命令行使用NUGET.EXE創建程序包。
然后我遇到了一個新問題。 通過使用NUGET.EXE而不是visual studio,生成的包將依賴項部分顯示為“不受支持”,這是通過在“ NuGet Explorer”中打開包看到的:
這是創建程序包的.bat文件:
c:\nuget\nuget.exe config -Set repositoryPath="%USERPROFILE%\.nuget\packages"
c:\nuget\nuget.exe pack -IncludeReferencedProjects -properties Configuration=Release
這是NUSPEC文件:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Integrative.Lara</id>
<version>0.5.3</version>
<authors>Pablo Carbonell, Integrative Software LLC</authors>
<owners>Pablo Carbonell, Integrative Software LLC</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<license type="file">LICENSE</license>
<projectUrl>https://github.com/integrativesoft/lara</projectUrl>
<iconUrl>https://integrative.b-cdn.net/Integrative.ico</iconUrl>
<description>Lara is ...</description>
<copyright>Copyright (c) 2019 Integrative Software LLC</copyright>
<tags>lara, web, html, html5, desktop, gui, cross, framework, mac, osx, platform, ui, blazor, razor</tags>
<repository url="https://github.com/integrativesoft/lara" />
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Microsoft.AspNetCore" version="2.2.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.WebSockets" version="2.2.1" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package>
有沒有辦法解決“不受支持”的目標? 我嘗試也使用“ netstandard2.0”和其他標識符,但仍然得到相同的“不受支持”。
另外,是否有一種方法可以使用Visual Studio的自動程序包生成,並防止它在程序包中包含文件?
如您所見,當您使用nuspec時,您有責任使每件事變得正確。 使用NuGet的MSBuild包目標更加容易,因為它可以自動執行諸如創建依賴項之類的工作,包括在組中使用正確的TFM。
關於打包目標的 NuGet的文檔中有一些與msbuild打包相關的內容(使用dotnet pack
或GeneratePackageOnBuild
時會發生這種情況)。 特別地,關於在包中包含內容的部分具有以下示例:
<Content Include="..\win7-x64\libuv.txt">
<Pack>false</Pack>
</Content>
由於文件是嵌入式文件,因此csproj將包含類似<EmbeddedResource Include="whatever.ext" />
。 因此,使用文檔中的信息,您可以執行<EmbeddedResource Include="whatever.ext" Pack="false" />
,或像文檔一樣使用多行版本。 MSBuild允許您以任何一種方式設置項目元數據。
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
關於GeneratePackageOnBuild的注釋:為您建立構建包很方便,但是這意味着,當您進行調試並且需要更改一行代碼然后再次進行測試時,不僅要等待構建,還要等待包。 如果您的程序包很小,則可能會很快,但仍然會減慢您的“內環”體驗。 大多數開發人員僅需要打包的次數就比其GeneratePackageOnBuild
次數少得多,因此我建議禁用GeneratePackageOnBuild
,而在您實際需要nupkg時在項目(或解決方案)上運行dotnet pack
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.