Creating Multiple Nuspec files - deployment

I am currently trying to publish a load of nuget packages for all the projects in this solution. The projects are setup in a simple tree, with Myre being the base project and everything depending on it:
Myre <- Myre.Debugging <- Myre.Debugging.UI <- Myre.UI
Myre <- Myre.UI
Myre <- Myre.Entities <- Myre.Graphics
I'm trying to package up each separate project as a nuget package with the correct dependencies on the other Myre subproject packages as necessary.
My first step was to make a package for Myre (nuspec and bat file of process). This seems to work nicely, the gallery shows Myre as having a ninject (another nuget package) dependency and all is well.
The problem comes when I tried to make the next package. Myre.Debugging depends upon Myre (with a normal project reference) and nothing else. Using this nuspec with nuget pack (verbose) gives:
Attempting to build package from '(x86) Myre.Debugging.csproj'.
Packing files from 'C:\Long_Path\Myre\Myre.Debugging\bin\x86\Release'.
Add file 'C:\Long_Path\Myre\Myre.Debugging\bin\x86\Release\Myre.Debugging.dll' to package as 'lib\net40-Client\Myre.Debugging.dll'
Add file 'C:\Long_Path\Myre\Myre\bin\x86\Release\Myre.dll' to package as 'lib\net40-Client\Myre.dll'
Add file 'C:\Long_Path\Myre\Myre\bin\x86\Release\Myre.XML' to package as 'lib\net40-Client\Myre.XML'
Found packages.config. Using packages listed as dependencies
Id: Myre.Debugging
Version: 1.0.0.2
Authors: Microsoft
Description: Description
Dependencies: Ninject (= 3.0.1.10)
Added file 'lib\net40-Client\Myre.Debugging.dll'.
Added file 'lib\net40-Client\Myre.dll'.
Added file 'lib\net40-Client\Myre.XML'.
Successfully created package 'C:\Long_Path\Myre\Myre.Debugging\Myre.Debugging.1.0.0.2.nupkg'.
As you can see it picks up a packages.config file (presumably from Myre since there isn't one here) which it then determines a Ninject dependency from. If I wanted Myre.Debugging and Myre to be a single package that would be fine. However this is not what I want, I want Myre.Debugging to pick up a dependency on the Myre package.
How can I setup nuget to use Myre as a package reference and not simply to copy the Myre assemblies into the Myre.Debugging package?
Edit:: I tried not using -IncludeReferencedProjects and specifying:
<dependencies>
<dependency id="Myre" version="1.0.0.1" />
</dependencies>
But for some reason this just creates a package with no dependencies at all! Even if manually specifying dependencies like this did work, it's hardly ideal.

According to the NuGet command line reference for the Pack command, the IncludeReferencedProjects switch works as follows:
Include referenced projects either as dependencies or as part of the package. If a referenced project has a corresponding nuspec file that has the same name as the project, then that referenced project is added as a dependency. Otherwise, the referenced project is added as part of the package.
In your case, Myre.Debugging.nuspec does not match the project file names: (x86) Myre.Debugging.csproj, etc. I suspect that you'll need to match up those file names to get that command line option to work.
Alternatively, if you want to get this to work with a <dependencies> element in your nuspec file, you may be facing another variant on the name mismatch problem. Your Myre.nuspec file defines its ID as follows:
<id>$id$</id>
The NuSpec reference says that the $id$ token is replaced by "The Assembly name." If it's talking about the name of the DLL (ignoring the extension), then I think the generated IDs will be (x86) Myre, etc. You might want to try hard-coding the ID temporarily just to see if that resolves the issue.
I haven't tried making these suggested changes, and I can't guarantee they will work, but I hope this points you in the right direction. Good luck!

Related

Trying to install package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references

I used NuGet Package Explorer (for the first time) to create a .nupkg to share with others. I have one DLL that targets NetStandardLibrary 2.0,
But when I try to add the package I receive the following error:
Could not install package 'iCANMVCSDK 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I thought that by using NETStandard 2.0 it could be installed in any .NET app. I also tried adding additional assemblies:
I rebuild, repackage, and I still get the same error. What am I missing?
I tried editing the project file like this:
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
When I try to build after adding net472, I receive the following error:
The type or namespace name 'Http' does not exist in the namespace 'System.Net'
What really makes no sense to me is that I can add the DLL directly into the project (the one that targes NET 4.72) and it works as expected. The problem is when attempting to install it as a NuGet package.

VSTS Automated Build NuGet Packager/Publisher

My package builds successfully and is uploaded to the Packages feed in VSTS however I can't seem to figure out how to edit the Description and Author of the package so that my set values show in the Package feed.
From what I read I put my content in the NuGet Packager under additional build properties and when I look at the log file I see this:
...NuGet.exe pack "...csproj" -OutputDirectory "..." -Properties Configuration=release;Description="My Description";Authors="Me";Owners="My Company"
From the documentation I believe I did this right(but clearly I did not). It does seem a bit confusing as to what goes in "Additional build properties" vs NuGet Arguments.
Again my goal is get the Description and Author that I set to be viewable from the NuGet Package Manager within Visual Studio.
You could create a package according to the .nuspec file.
Steps:
Generate .nuspec file for your project (command: nugget spec).
For example: (Include author and description token)
<?xml version="1.0"?>
<package >
<metadata>
<id>CommLib1</id>
<version>1.0.0.6</version>
<title>CommLib1</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
Include this file to source control
Specify Nuget Arguments (token in step 1) of Nuget Packager build step
Update1:
In general, you just need to update AssemblyInfo.cs file of your project (Author=>AssemblyCompany; Description=>AssemblyDescription; Version=>AssemblyVersion), it creates package according to this data unless it can't retrieve metadata from your assembly (I have a project has this issue).
So, steps:
Make sure nuget could retrieve necessary metadata by creating package through nuget.exe command directly in your local/build machine (nuget pack [XX].csproj)
Create a build definition (1. Visual Studio Build 2. Nuget Packager with default value 3. Nuget Publisher)
If it's building the package then there are no problems with your NuGet Packager build step. Two things need to change though.
In order to specify properties like you are doing there MUST be a tokenized *.nuspec file in the same directory as the solution file with the same name and of course the *.nuspec file needs to be checked in to VSTS/TFS.
The token name for description can't be Description.
For more details on the *.nuspec file please see the solution here:
Nuget.exe pack WARNING: Description was not specified. Using 'Description'

Reference not added for NuGet package

I've a custom NuGet package (My.Resources) containing an assembly and a dependency on another custom NuGet package (My.Base).
If I install the package, the installation finishes successfully, but the assembly reference is not added. Here is the full output from a Install-Packagecommand:
Attempting to resolve dependency 'My.Base (≥ 1.0.0)'.
Installing 'My.Base 1.0.0'.
Added file 'My.Base.dll' to folder 'My.Base.1.0.0\lib\net45'.
Added file 'My.Base.1.0.0.nupkg' to folder 'My.Base.1.0.0'.
Successfully installed 'My.Base 1.0.0'.
Installing 'My.Rsources 1.1.0-beta0001'.
Added file 'My.Resources.dll' to folder 'My.Resources.1.1.0-beta0001\lib\net45'.
Added file 'My.Resources.XML' to folder 'My.Resources.1.1.0-beta0001\lib\net45'.
Added file 'My.Resources.1.1.0-beta0001.nupkg' to folder 'My.Resources.1.1.0-beta0001'.
Successfully installed 'My.Resources 1.1.0-beta0001'.
Adding 'My.Base 1.0.0' to WindowsFormsApplication8.
For adding package 'My.Base 1.0.0' to project 'WindowsFormsApplication8' that targets 'net45',
>> Assembly references are being added from 'lib\net45'
Added reference 'My.Base' to project 'WindowsFormsApplication8'
Added file 'packages.config'.
Added file 'packages.config' to project 'WindowsFormsApplication8'
Successfully added 'My.Base 1.0.0' to WindowsFormsApplication8.
Adding 'My.Resources 1.1.0-beta0001' to WindowsFormsApplication8.
Added file 'packages.config'.
Successfully added 'My.Resources 1.1.0-beta0001' to WindowsFormsApplication8.
While we have several other custom NuGet Packages structured and build the same way, this is the only one with this behavior. The .nuspec inside the .nupkg looks fine and the assembly is in the correct (net45) folder.
NuGet is treating your NuGet package as a localized NuGet package that only contains language resources. Assemblies in this sort of NuGet package are not referenced.
If you rename your My.Resources.dll to something like My.Resources2.dll, for example, then NuGet will reference the assembly.
Basically any file that ends with .resources.dll is considered by NuGet to be a resource assembly will not be referenced when the NuGet package is installed.

Avoid dependency of a pure code snippet package

Example:
Nuget package A is a set of code snippets (it does not contain an assembly).
Nuget package B is a normal assembly and it is using package A - just for internal means.
Question: What can I do, to avoid, that package A is also installed, when somone installes package B?
Found something in documentation of nuget:
Starting from version 2.7, the pack command will ignore entries in the packages.config file which have an attribute developmentDependency set to true and will not include that package as a dependency in the created package. For example, consider the following packages.config file in the source project
That seems to solve the problem.

NuGet Assembly outside lib folder

I'm going to bang out a couple of questions here...first, with NuGet is it possible to create a package from a few DLLs? There is no visual studio project, just the command line and a couple of pre-compiled DLL files.
Second, assuming that is possible, why do I continuously get the "Assembly outside of the lib folder" warning? I've tried everything I can think of to get associated assemblies to add themselves as references inside of the NuGet package.
My file structure looks like this
Root
- File1.dll
- lib
- File2.dll
- File3.dll
When I tell NuGet to pack it using a .nuspec like this
<?xml version="1.0"?>
<package >
<metadata>
<id>File1.dll</id>
<version>1.0.0</version>
<authors>thisguy</authors>
<owners>thisguysmom</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is some library</description>
<releaseNotes>Porting to NuGet</releaseNotes>
<copyright>Copyright 2012</copyright>
<references>
<reference file="File2.dll" />
<reference file="File3.dll" />
</references>
</metadata>
</package>
I receive that warning. From what I'm reading, I shouldn't even have to define the references node in any of my projects, as the lib folder items should automatically be added as references?
Does anyone out there understand this NuGet mess?
I just ran into this problem. Nuget is expecting a structure that looks like:
root
- lib
- net40
- File1.dll
- File2.dll
- File3.dll
net40 or net20 or net45 as appropriate to your .net version.
run
nuget pack yourlibrary.nuspec
to package it up.
That will pack up the dir wholesale and put it in the nupkg. The error messages will disappear at that point.
Any dll that you want referenced should be under the lib folder. The warning is because file1.dll is outside lib and will be ignored during package installation. (Other special folder are "content" and "tools")
I'd used this structure :
Root
- lib
- File1.dll
- File2.dll
- File3.dll
See : http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Package_Conventions for additional details.
With the version of NuGet that is current as of this post (and I assume later versions as well), you can use the .csproj file, in tandem with the .nuspec file to create the package. What we did was make a .nuspec file (using nuget spec and then customizing it) and include it in the project.
With the customized .nuspec file, we used the command:
nuget pack sample.csproj -IncludeReferencedProjects
At that point it built the .nupkg and did not emit issues. The .nupkg file showed up in the normal output folder (in my default case, bin\debug).
You may add references to another dll by adding below inside tag in nuspec file
<package>
<metadata>
...
</metadata>
<files>
<file src="..\ReferencedFolder\*.*" target="lib\net40\" />
</files>
</package>
Alexandre is referring to the "lib" folder that gets created when you create a NuGet package. You can open the .nupkg just like you would any zip file. In there, you will see a lib\netXX folder where XX is the version of the .NET framework you're targeting. So when you're packing your NuGet file, make sure File1.dll is inside the lib folder.
I used Prof Von Lemongargle' solution, and for me was a great solution.
Important:
Include spec file (with right-click-> Include in project) in the project
Give to spec file THE SAME FILENAME of your project (myproject.csproj, myproject.nuspec)
This work perfectly in Visual Studio 2012.
They get into the "lib" folder by being included in your bin\debug or bin\release folder in .NET. So you need to get the project compile to copy local on the external DLLs so it includes them in the bin folder on compile.
If dependencies or libraries have been changed, old files affect the packaging operation.
Remove obj and bin folders from project.
Run dotnet restore
Run nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects or your command whatever.