Nuget package generation Exclude lib folder

TorontoKid picture TorontoKid · Dec 2, 2013 · Viewed 13.8k times · Source

I am trying to generate nuget package with .nuspec file. We have several projects under one roof and trying to create nLog.config (And transform files) and distribute it via nuget package. For any version of .Net Framework I am looking for same set of config files (only configs no dll). So I really don't require \lib\net45\myproject.dll or \lib\net40\myproject.dll. Though when I generate nuget package it always create lib folder and include dll. Which sort of create dependency for any project related to .net framework version.

Below is my nuspec file in case if someone wants to refer if I am doing something wrong. I tried "" and few other things but no luck.

<?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>

How can I exclude lib folder completely using nuspec file (Preferred) or other mechanism? Thanks !!

enter image description here

Update 1:

I tried to sneak but was not successful. I put post build event and tried to delete DLL. But somehow system was smart it gave me error "Error 79 Unable to find 'C:\GITRepo\NLogConfig\NLogConfig\bin\Release\NLogConfig.dll'. Make sure the project has been built."

Update 2

I didn't found way around using .csproj to build nuget package but using external command and specifying nuspec file I was able to achieve same results. Question still remains this is my workaround only.

Answer

AndreyCh picture AndreyCh · Apr 19, 2017

I wanted to share my experience. What I needed was to use csproj as Nuget.exe target (since I wanted NuGet to resolve dependencies automatically) and no lib folder in a result package. To omit that folder I used the following command:

nuget pack <projectPath> -Exclude bin/**/*.*