Install nupkg from local nuget package - c#

I have followed http://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx this guide to create my own nuget package. The only problem is when i use the console to install my package it just adds the cs files directly to the project instead of createing a .dll and add it as a package. The content folder of my nuget only contains two cs files is that why it doesn't create the package as a dll and instead just uses the cs files directly?

Look at your original nuspec file for whether it's including the output DLLs or the raw CS's (probably the latter). Fix it and make sure the assemblies go into lib/netXX (e.g. lib/net45), not "content".
Also, the file is just a ZIP. Inspect it before you use it to ensure that it contains the right files.

Related

Nuget package extraction without build

I have my own Nuget package and I want to "extract" it (get the dll inside it) without building the project.
Is it possible?
Can I do it to a specific folder?
If it is possible:
can I do it on "Nuget restore", "Nuget installation", project reference (when adding the project with the Nuget as a reference to other project)?
Is it possible to do a post-process such as writing the path of the extract dlls to a file?
Thanks.

Patch assembly and nuget version of each project independently

I have a solution with multiple projects (each is a nuget package for some common utils).
I want to build all these projects in VSTS.
The problem each project has a unique version.
version.txt file is stored in each project's folder, and contains the version in format x.x.x
before build each project should be patched with this version
build and push nuget packages
VSTS contains task dotnet build which can build an entire solution or a concrete project. But I need to automate this process - once the new project was added it should be built automatically.
I didn't find the ready-to-use build task which can read the file and patch all parameters of csproj (FileVersion, AssemblyVersion, Version, PackageVersion), and do this per project.
It would be great to have this version.txt file to have a single point of configuration (instead of changing all the parameters)
I didn't find the ready-to-use build task which can read the file and
patch all parameters of csproj (FileVersion, AssemblyVersion, Version,
PackageVersion), and do this per project
Actually, you can get AssemblyFileVersion and AssemblyVersion easily by related task (such as Assembly Info Reader task).
You just need to specify the path for AssemblyInfo.cs file, then you can get the AssemblyFileVersion by the variable $(ASSEMBLYINFO.ASSEMBLYFILEVE), and get the AssemblyVersion by the variable $(ASSEMBLYINFO.ASSEMBLYVERSION). And you can use the version for the package.
BTW: the packed packages use it's AssemblyVersion by default. So if you want to packages use their AssemblyVersions, there is no need to do additional settings.
I did not find the solution so invented a new bicycle.
In each project folder there is a version.txt file with the version of exact package
Powershell scripts finds all version.txt files and uses the version from the file to patch .csproj file (package, assembly, whatever)
build all projects
In my scenario I don't want to add build number to the version so I have packages with the same version over builds. So I want to skip already exist packages
With Powershell script I do nuget list <package name> to check whether package already exists.
If not - pushing it to the repository.

Create nuget package with shared assemblyinfo in other folder

I'm working to try to get some of my companies older code into packages. Several of the common components, considered "core", use a common file with assemblyinfo attributes from a shared folder. The file included as a link in the project. How do I get nuget to use the information in that file? For example, this file contains the assembly version instead of the "assemblyinfo.cs" file in the project. So nuget throws an error about how it can't find a replacement for the $version$ identifier.
What I've done to get this to work is by using
nuget pack [projectFile].csproj
which will use the combined AssemblyInfo and the SharedAssemblyInfo file. I put both of these files in the Properties portion of the project.

How do I tell 'nuget pack' that I don't want a content folder in the package?

I'm creating a nuget package from a C# project using the following command:
nuget pack project.csproj -Prop Configuration=Release
However when I inspect the contents of the package, it appears to have included some .tt files which causes any projects that use this dependency to fail to build unless the .tt files are removed.
Is there any way to tell nuget not to create a content folder or to stop these .tt files from being included?

How to tell nuget to add package resource files as links, and not copy them into project directory

Intro (how to pack resources into a nuget package)
To pack some resource files into a nuget package, what one would normally do, is the following.
Put all the resource files into the content\ directory of a nuget package. This would be specified by the following line in a .nuspec file:
<files>
<file src="Project\bin\Release\script.js" target="content\js\script.js" />
<files>
Now, when this nuget package gets installed into AnotherProject, the following file structure emerges:
Solution.sln
packages\Project.1.0.0\content\js\script.js // the original resource file
AnotherProject\js\script.js // a physical copy
AnotherProject\AnotherProject.csproj // <Content /> tag (see below)
During package installation, AnotherProject.csproj was injected with tag:
<Content Include="js\script.js" />
and this is for the physical copy of the original resource (which is under packages\ directory).
The actual problem (how to pack resources into a nuget package as link)
My aim is not to have the physical copy of a resource file in the AnotherProject directory but rather a "link" to the original resource under packages\ directory. In the csproj, this should look like this:
<Content Include="packages\Project.1.0.0\content\js\script.js">
<Link>js\script.js</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Brute force solution that I would rather avoid
Now, one "do it the hard way" workaround I can think of is:
not putting resource files under content\ so they do not get added automatically,
writing Install.ps1 script that would hack the csproj file structure and add the necessary XML piece manually,
This, however, has the following drawbacks:
all my nuget packages need the same script piece in their Install.ps1,
when installing my packages, there would be a nasty "project reload prompt" in Visual Studio.
Since NuGet currently does not support this out of the box your options are either to use PowerShell or to use a custom MSBuild target.
PowerShell
Leave your resources outside of the Content directory in your NuGet package (as you already suggested).
Add the file link using PowerShell in the install.ps1.
You should be able to avoid the project reload prompt if you use the Visual Studio object model (EnvDTE). I would take a look at Project.ProjectItems.AddFromFile(...) to see if that works for you.
MSBuild target
NuGet supports adding an import statement into a project that points to an MSBuild .props and/or .targets file. So you could put your resources into the tools directory of your NuGet package and reference them from a custom MSBuild .props/.targets file.
Typically the custom .props and .targets are used to customise the build process. However they are just MSBuild project files so you could add items for your resources into these project files.
Note that .props are imported at the start of the project file when a NuGet package is installed, whilst .targets are imported at the end of the project.
Customising NuGet
Another option, which would take more work, would be to modify NuGet to support what you want to do.

Categories