Nuget包生成Exclude lib文件夹

Tor*_*Kid 22 .net c# nuget nuget-package visual-studio-2012

我正在尝试使用.nuspec文件生成nuget包.我们在一个屋檐下有几个项目,并尝试创建nLog.config(和转换文件)并通过nuget包分发它.对于任何版本的.Net Framework,我正在寻找相同的配置文件集(只配置没有dll).所以我真的不需要\ lib \net45\myproject.dll或\ lib \net40\myproject.dll.虽然当我生成nuget包时,它总是创建lib文件夹并包含dll.对于与.net框架版本相关的任何项目,哪种创建依赖关系.

下面是我的nuspec文件,以防有人想提及我做错了什么.我试过""和其他一些事情,但没有运气.

<?xml version="1.0"?>
<package >
  <metadata>
    <id>NLogConfig</id>
    <version>1.0.3</version>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <copyright>Copyright 2013</copyright>
    <dependencies>
      <dependency id="NLog" version="2.1.0" />
      <dependency id="NLog.Schema" version="2.1.0" />
    </dependencies>
  </metadata>
  <files>    
    <file src="NLog.config" target="content" />
    <file src="NLog.Debug.config" target="content" />
    <file src="NLog.UAT.config" target="content" />
    <file src="NLog.Release.config" target="content" />
    <file src="tools\*.*" target="tools"/>          
  </files>
</package>
Run Code Online (Sandbox Code Playgroud)

如何使用nuspec文件(首选)或其他机制完全排除lib文件夹?谢谢 !!

在此输入图像描述

更新1:

我试图偷偷摸摸但没有成功.我把post build事件和试图删除DLL.但不知何故系统很聪明,它给了我错误"错误79无法找到'C:\ GITRepo\NLogConfig\NLogConfig\bin\Release\NLogConfig.dll'.确保项目已经建成."

更新2

我没有找到使用.csproj来构建nuget包的方法,但是使用外部命令并指定nuspec文件我能够获得相同的结果.问题仍然存在,这只是我的解决方法.

And*_*yCh 11

我想分享一下我的经历.我需要的是使用csproj作为Nuget.exe目标(因为我希望NuGet自动解析依赖关系)并且结果包中没有lib文件夹.要省略该文件夹,我使用以下命令:

nuget pack <projectPath> -Exclude bin/**/*.*
Run Code Online (Sandbox Code Playgroud)


小智 7

使用NuGet Pack命令选项-Tool.请参阅https://docs.microsoft.com/en-us/nuget/tools/cli-ref-pack.

"确定项目的输出文件是否应该在工具文件夹中."


Dav*_*ans 5

我首先从项目的输出文件夹中排除了所有文件,从而解决了这个问题

<file src="bin\**\*.*" target="lib\net451" exclude="bin\**\*.*" />
Run Code Online (Sandbox Code Playgroud)

然后,当通过NuGet.exe实际打包时,我的目标是.nuspec而不是 csproj。生成的软件包在/ lib文件夹下不包含我项目的输出dll。


小智 0

您可以使用排除语法将 lib 文件保留在包中。像下面这样:

<files>
<file src="bin\Debug\*.*" exclude="bin\Debug\*.dll" />
</files>
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅http://docs.nuget.org/docs/reference/nuspec-reference