Package all content from a folder using NuGet - nuget

We would like to use Octopus Deploy for our Deployments. I am trying to package our assemblies using Nuget for the same. We maintain lots of solutions (contains lots of independent projects) and We have our custom windows host which doesn't have any direct reference to the application assemblies. Currently We Zip all the files and extract them to install the windows services. I am exploring a way to package all the content in zip file to NuGet Package. is that possible. What is the best and easiest way to package considering our current implementation. I tried creating .NuSpec file and NuPkg manually using package explorer. But it's not visible and only visible in package explorer.

you can bundle all artifacts by defining metadata inside a nuspec files , nuget package created using that nuspec file will contain all artifacts defined in nuspec file, you can do the whole process from your command line as well , when creation of package is done from command line you can see your package in the same path where nuspec file resides and most important thing nuget package is also a type of zip file , so you can simply rename your example.nupkg to example.zip and verify the bundled contents.

Related

How can I deploy a PS1 script with a nuget package

I have a PS1 script that I use in all my projects to sign the assemblies. Until now I copied this file over to all my projects. Now I wanted to create a nuget package with the PS1 file.
I created a nuspec file and put the file in "content". Unfortunately nothing happened. Then I tried to put it in lib. Still noting happened. When I restore the package in my project no files where created in this project.
When I analyst the nupkg file with my 7-Zip the file looks OK. The ps1 file was in content, lib respectively.
I didn't found anything to this topic online. Can someone explain to me, how to create such a NuGet-Package?
When a project using packages.config installs a NuGet package, the package's tools\install.ps1 script will run. However, this no longer happens when the project using the package uses PackageReference (such as SDK style projects, used by .NET Core).
Similarly, the files in the content folder of the nupkg are copied into the project on install, but only when the project uses packages.config. PackageReference projects use the contentFiles folder in the nupkg, however the behaviour is different. Those files are copied only on build, not install, for .NET Framework projects and on publish for .NET Core projects. Probably not what you want for signing assemblies.
The feature you probably want to use is including MSBuild props and targets in your package. Note that the props and targets file names must match the package id exactly for NuGet to use them. You probably want to use afterTargets="build" at a guess.

How are lib files referenced in Nuget Package Explorer

When I add a file to my Nuget package under the lib folder using the Nuget Package Explorer, I select the file via a standard file dialog. So I add all the files under the desired platforms... simple.
My question is, since there is nothing in the Nuget Package Explorer that tells me the source path of each file, do I have to re-add the files when I make changed to my files? For example, version 1.0.0 of "MyNugetPackage.nupkg" has a "net45" lib folder and 1 DLL, MyDll.dll. I make some changes to MyDll.dll and want to update MyNugetPackage to version 1.0.1. Do I have to delete the MyDll.dll from the net45 folder and re-add it? Do I need to create a whole new Nuget package? Or does the existing reference just point to the new MyDll.dll?
NuGet Package Explorer edits an existing .nupkg file which is basically a .zip file. If you change your dll then it will not automatically be included the .nupkg so yes you would need to add your dll again into the .nupkg if you are using NuGet Package Explorer.
Instead I would look at using the NuGet pack command either with a .nuspec file or a project file (.csproj) which can be used to create a .nupkg file each time instead of manually editing the .nupkg in NuGet Package Explorer.

How does NuGet decide which files are included when packing a csproj file?

I'm trying to use the simplest and most automated approach possible to create a few NuGet packages from some of our projects, by using the nuget pack [path-to-csproj] method.
For most of the projects I've tried this, the command line tool seems to understand the .Net framework version of the projects and it adds the output dll and xml files to the correct lib folder. In some other project, it is including a .css file to the content folder in the package, I assume because the file has a Content build action.
What exactly does this NuGet command include in the final package and how does it extract this information? Is there a comprehensive documentation on the file extraction from the csproj? I'd like to understand this process so that I can hopefully add my own files to it, like the app.config file and some code contracts assembly files without having to hardcode paths in the nuspec definition.

Creating folder with contents in project root

I developed a tool that besides DLL requires a strong named folder with 2 files in solution. Using NuGet GUI I created the folder and populated with files, but when I install package, the only DLL created but folder with 2 files are not. How can that be fixed?
NuGet has a set of conventions that define certain folders inside the NuGet package that will result in different actions being taken when the package is installed or uninstalled.
In order for folders to be created inside the project, when the NuGet package is installed, the folders need to be inside a Content directory. If you look at the jQuery package, it has a Content\Scripts folder with files inside it. This Scripts folder will be created inside your project, along with its files, when you install the jQuery NuGet package.
\Content
\Scripts
\jquery-2.1.0.js

Is there a way to specify Build Action=None with nuspec?

My company has an assembly versioning package that I've written in powershell and is distributed amongst my colleagues via our internal nuget feed.
There are a couple of template files which can be user-modified after the package in installed. These files are being included in the package which we generate via
nuget pack xxxx.csproj
We've done a little investigation and there files are not packaged when we change the Build Action to None.
Is there a way to tell nuspec to add the files to the project with Build Action set to None*?
Alternatively is there a way to tell nuget pack to not include certain files in the package in generates?
NuGet pack has an Exclude parameter that can be used to filter out files that you don't want in your package.
If you want to include files that are auto excluded from your project then you need to add a nuspec to your project and add a element that includes that file.
More information here:
http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_project
http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command
nuget pack will ignore any files or folders that start with period/full stop. So one easy way would be to rename your template files or the folder they are located in to start with a period/full stop if possible.