Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget package generation Exclude lib folder

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.

like image 573
TorontoKid Avatar asked Dec 02 '13 20:12

TorontoKid


4 Answers

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/**/*.*
like image 165
AndreyCh Avatar answered Oct 18 '22 19:10

AndreyCh


Use the NuGet Pack command option -Tool. See https://learn.microsoft.com/en-us/nuget/tools/cli-ref-pack.

"Determines if the output files of the project should be in the tool folder."

like image 28
Tomáš Veselý Avatar answered Oct 18 '22 20:10

Tomáš Veselý


I solved this problem by firstly excluding all files from my project's output folder

<file src="bin\**\*.*" target="lib\net451" exclude="bin\**\*.*" />

And then when actually packaging via NuGet.exe I targeted my .nuspec and not my csproj. The resulting package did not contain my project's output dll under a /lib folder.

like image 39
Dav Evans Avatar answered Oct 18 '22 20:10

Dav Evans


This is expected behavior when you pack by a project, as the whole point is that nuget will read the project and generate a package accordingly. And any .nuspec that is found will only be able to add content, not remove any previously added.

So what you note is your second update is what you are supposed to do - pack by the .nuspec instead.

like image 41
Alex Avatar answered Oct 18 '22 20:10

Alex