Rename nuget package content file as per target project - nuget

While installing my custom Nuget package to target cs projects, I need to rename few content files as per the target project name. E.g. If the target project name is "XYZ.Model" then my Nuget package content file should be installed as "XYZ.Model.EF.tt".
Any help is appreciated.
Thanks

Handled this via POSH script which is part of my nuget package.

Related

Nuget Package Without Lib-Ref-Content Folders

I have downloaded an open source project, made changes to it and then created a nuget package from this new code. The package actually functions as a post-build target. It just runs an exe. That is why it does not contain a lib folder. There is a tools folder and files are copied under this folder. The other folders are: build, buildCrossTargeting, package, _rels. .But when I try to install this local nuget package to a .net 4.6.1 project, I get the following error in Visual Studio:
You are trying to install this package into a project that targets
'.NETFramework,Version=v4.6.1', but the package does not contain any
assembly references or content files that are compatible with that
framework.
When I open and inspect the original nuget package downloaded from nuget.org, I see the same structure. But somehow it installs fine while this locally created one raises error.
What can be done about it?
With the information you provided, I can only guess (please see How to create a Minimal, Reproducible Example). My guess is that you changed the name (id) of the package, but didn't change the name of the target or props files in the build directory. As the docs say, the name of the targets and props file must match the package id exactly, so if you change the package id, you must rename those files.

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.

Package all content from a folder using 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.

NuGet and Portable Class Libraries - Package doesn't target any framework

I have been using NuGet to manage my internally created assemblies for a few months, and it's working very well. I recently 'discovered' portable class libraries, which has also been great - until it's time to install the packages.
Say I have a PCL that targets .NET 4.5, SL5 and .NET for Windows Store Apps. I run nuget spec to create the .nuspec file, edit the values, package it up, and add the .nupkg to our internal feed. If I open the .nupkg file in the Package Explorer, I see one content folder under lib called portable-win+net45+sl50.
When I try to install the package from any compatible project in another solution, I get the following message:
"'Project.PCL' could not be installed because it is not compatible with any project in the solution. The package doesn't target any framework."
If I manually create the .nupkg in the Package Explorer, updating the version number, adding a lib folder for each targeted framework (not a portable folder) and added the Project.PCL.dll to each folder, I can add the package to the compatible projects in the solution. But to do this process every time I want to update a PCl is somewhat tedious (I had been creating a little .cmd file in the project root folder to quickly package and deploy).
Do other people have this problem? How can I package PCL's in the same way as other types of projects?
Note - I'm using VS 2012 Ultimate and NuGet 2.2
It sounds like maybe nuget spec doesn't work for Portable Class Libraries - that's worth starting a thread or filing an issue on the NuGet site.
However, you can also create a .nuspec file from NuGet Package Explorer. Just create the package as you already did, but then choose "Save Metadata As..." to save it as a .nuspec. Afterwards you may need to edit the source paths in the nuspec file manually, but you should be able to automate the creation of the package.
For me nuget spec and nuget pack worked fine with a portable project while creating the package and installing it on a compatible project.
Do you want to check if you have the latest nuget.exe (2.2), it can be downloaded from http://nuget.org/nuget.exe or can be updated by running nuget update -self

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.