簡體   English   中英

使用 dotnet pack 創建具有依賴項但沒有我自己的代碼的 NUGET

[英]Using dotnet pack creates NUGET with dependencies but without my own code

我有一個簡單的 .NET Core 3.1 class 庫,它在類中實現了一些日志記錄功能,並有一個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 的兩個依賴項,但package 中沒有包含我的實際代碼(在我的類中)

在此處輸入圖像描述

似乎 NuGet 不知道實際構建什么。 我錯過了什么?

創建 Nuget package (*.nupkg) 時,您必須定義要包含在該 package 中的所有文件。 在 nuspec 配置中,您缺少以下內容:

<files>
   <file src="bin\Debug\*.dll" target="lib" />
</files>

其中bin\Debug\是構建的 output 路徑。 如需進一步參考,請訪問文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM