ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C#-dotnet pack命令以及nuspec文件不包括项目的DLL

2019-11-08 15:05:16  阅读:759  来源: 互联网

标签:net-standard nuget c net


我有一个使用ProjectName.Logging.nuspec文件的名为ProjectName.Logging的.NET Standard 2.0项目.

我的项目的.csproj中引用了此文件文件

<PropertyGroup>
  <TargetFramework>netstandard2.0</TargetFramework>
  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  <NuspecFile>ProjectName.Logging.nuspec</NuspecFile>  
</PropertyGroup>

这是我的.nuspec

<?xml version="1.0"?>
<package >
    <metadata>
        <id>ProjectName.Logging</id>
        <version>1.2.1</version>
        <authors>Jérôme MEVEL</authors>
        <description>Just a logging component</description>
        <dependencies>
            <dependency id="Dapper" version="1.50.5" />
            <dependency id="Another.Project" version="1.1.1" />
            <dependency id="Microsoft.Extensions.DependencyInjection" version="2.1.1" />
            <dependency id="Microsoft.Extensions.Logging" version="2.1.1" />
            <dependency id="Microsoft.Extensions.Logging.Abstractions" version="2.1.1" />
            <dependency id="NLog" version="4.5.8" />
            <dependency id="NLog.Extensions.Logging" version="1.2.1" />
            <dependency id="NLog.Web.AspNetCore" version="4.6.0" />
            <dependency id="System.Data.SqlClient" version="4.5.1" />
        </dependencies>
    </metadata>
    <files>
        <file src="bin\Release\netstandard2.0\ProjectName.Logging.dll" target="lib/netstandard2.0/ESHCloud.Logging.dll" />
        <file src="ProjectName.Logging.targets" target="build/ProjectName.Logging.targets" />
        <file src="NLog/Nlog.config" target="content/Nlog.config" />
    </files>
</package>

如您所见,我手动包含ProjectName.Logging.dll文件,甚至必须包含Release,因为MsBuild变量$(Configuration)的用法在我的.nuspec文件中不起作用.

我通过在项目目录中执行此命令来打包项目

dotnet pack --output C:/Nuget --force

如果我删除了< files>当我运行dotnet pack命令时,来自.nuspec元素,我生成的Nuget包完全为空.

另一方面,如果我在没有.nuspec文件的情况下运行dotnet pack命令,则项目中的所有内容绝对都包含在Nuget包中.

那么dotnet pack命令有什么用呢?我不明白我在做什么错.

如何在不指定配置(调试或发行版)的情况下将项目的DLL包含在Nuget包中?

最后一件事:我不想使用nuget pack命令.

我在VSTS服务器(最近重命名为Azure DevOps)上与Nuget一起玩够了,但我对这些构建服务器没有完全的控制权(我的经理可以控制,但他似乎太忙了以至于无法关心它).

综上所述,nuget pack对我来说不是一个选择.我想将dotnet pack与.nuspec文件一起使用.

谢谢

解决方法:

要添加DLL而不指定配置,请使用全局模式:

<file src="runtimes\**" target="runtimes/"/>

如果使用nuget.exe,则可以使用replacement token

<file src="bin\$configuration$\netstandard2.0\*.dll" target="lib\netstandard2.0\"/>

如果您确实需要使用nuspec文件,那么最好使用nuget.exe.如果您不想使用nuget.exe,请删除nuspec.我在过去几周用dotnet和nupkgs完成了a fair amount of work,将nuspec与项目文件混合起来很简单.

您可以将majority of the nupkg meta-data直接放在csproj中:

<PropertyGroup>
  <PackageId>Subor.nng.NETCore</PackageId>
  <PackageVersion>0.0.2</PackageVersion>
  <Authors>Subor</Authors>
  ...
</PropertyGroup>

这是the recommended approach when using the dotnet CLI.PackageReference格式的Likewise for msbuild.

Here’s an example of a project我一直在努力. dotnet pack构建软件包bin / Debug /和dotnet pack –configuration版本构建this nuget.org package.

项目中的所有内容都不应复制到nupkg中.在Visual Studio中,检查文件的属性,并确保所有内容均未标记为“内容”等.还要检查项目文件,以查看是否正在添加不应添加的文件.查找&miss PackagePath>的(miss-)使用和< IsPackable>.

在不知道您的项目细节的情况下,我会提到尝试arguments to dotnet pack的一些功能.

标签:net-standard,nuget,c,net
来源: https://codeday.me/bug/20191108/2008878.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有