NuGet Pack: ignoring by default enables

This is the opposite problem from what I usually read, these are people trying to get the files included in the NuGet package. I am trying to disconnect a file automatically.

I am creating a library of pre-compiled MVC view templates (using RazorGenerator.Mvc), .less files and JavaScript to support them as needed. The idea is that these are the main things that go into all of our sites.

By default, nuget pack includes any files marked as “Build action: content in your project” that will have any newly created view, .less file or script. There seems to be no way to override this behavior. In this question, the presented solution of the empty <files> node in .nuspec to stop everything includes , but I want to include some files, only the ones that I select.

Now, as a period of time, I can go through, explicitly establish that everything is not Content ("No" is used instead), and then explicitly configure the files that I make and do not want to copy, and where I want them to be copied using the .nuspec file. However, if another developer appears, for example, my future, and forgets this step, then the newly added files will be copied to the package, and then to the destination project during the next installation or update.

I found OctoPack and this will include nothing by default once it detects the <files> node in .nuspec , but I do not use anything from TeamCity, and rewrite the scripts of my build server to figure out how to call OctoPack instead of nuget pack does not make me a great option. OctoPack also has limitations; dependencies must be listed manually, replacement tokens for the .nuspec file must be passed on the command line (instead of reading from AssemblyInfo.cs ), and it just doesn't seem like the tool was intended for this use - they even say: "OctoPack should only be installed the projects you’re about to deploy are console application projects, Windows Service projects, and ASP.NET web applications. Unit tests, class libraries, and other supporting projects will not be selected. " ( OctoPack Documentation )

The following alternative I tried was to use msbuild to simply destroy the Content group during the BeforeBuild event:

 <Target Name="BeforeBuild"> <ItemGroup> <Content Remove="**\*.*" /> <None Include="**\*.*" /> </ItemGroup> <Message Text="Content files: @(Content)" Importance="High" /> </Target> 

The message verifies that the content group is empty, but the nuget pack does not seem to care; it includes all the files anyway.

Someone has successfully created such a package, without having to manually flag everything. Build action: no, and without using OctoPack?

+6
source share
2 answers

It seems that if you call nuget pack MyProject.nuspec (instead of nuget pack , which will look for both .csproj and .nuspec ), you can get the desired behavior, although you still (for example, with OctoPack) lose the token replacement and automatic addictions. So this is not an ideal solution that would be something like --no-default-content , but it works pretty well.

nuget pack MyProject.nuspec -Properties version={XYZ} (where XYZ is populated by the build server), at least let me make sure the version number is also incremented correctly. For example, I could install in .nuspec

<version>1.1.0.$version$</version> and just use the SVN version as the last part.

+5
source

Another solution (still not perfect, but at least you can continue to transfer the .csproj file and not lose its advantages) is to delete the contents folder of the resulting .nupkg file (by treating it as .zip).

An easy way to do this is through a script as follows:

Delete files from .zip file with Powershell

Please note that System.IO.Compression - used by this script - works only with PowerShell 3.0 and .NET 4.5.

0
source

Source: https://habr.com/ru/post/980934/


All Articles