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 !!
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.
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/**/*.*
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."
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With