我有一個簡單的 .NET Core 3.1 類別庫,它在類中實作了一些日志記錄功能并有一個nlog.config檔案。在.csproj這個樣子的
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>Sima.Logging.nuspec</NuspecFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.7.12" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
</ItemGroup>
</Project>
如您所見,我.csproj參考了一個.nuspec檔案。我需要這樣做是因為我想將其nlog.config作為內容檔案包含在內。在.nuspec這個樣子的
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Sima.Logging</id>
<version>1.0.0</version>
<contentFiles>
<files include="**/nlog.config" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
<dependencies>
<group>
<dependency id="NLog" version="4.7.12" exclude="Build,Analyzers" />
<dependency id="NLog.Web.AspNetCore" version="4.9.3" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
<files>
<file src="contentFiles\**" target="contentFiles" />
</files>
</package>
使用 打包我的庫后dotnet pack,nupkg 只包含 NLog 的兩個依賴項,但我的實際代碼(在我的類中)沒有包含在包中。

似乎 NuGet 不知道實際構建什么。我錯過了什么?
uj5u.com熱心網友回復:
創建 Nuget 包 (*.nupkg) 時,您必須定義要包含在該包中的所有檔案。在 nuspec 配置中,您缺少以下內容:
<files>
<file src="bin\Debug\*.dll" target="lib" />
</files>
bin\Debug\構建的輸出路徑在哪里。如需進一步參考,請訪問檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/361503.html
