Custom NuGet Package Install Output Window Messages - c#

When I install my custom NuGet package it works, but the output window in VS shows messages like it tried to add the files twice and they already existed. Output is further down in this post.
I have a NuGet private repository on a server here that is working to host our gallery. Installs and uninstalls are working, even though the output window shows the messages below. I am curious about the <files> tag in the spec file and if there's a different way I need to do this. I have tried multiple ways based on the documentation. My version is up to date installed from the NuGet site.
From the site: The latest version of the nuget.exe command-line tool is always available from http://nuget.org/nuget.exe
Specifying files to include in the package
The output window shows things like this on Install-Package CustomNuGet:
The item /Plugins/CustomNuGet/CSS/custom.css already exists.
The item /Plugins/CustomNuGet/Scripts/custom.js already exists.
The item /Plugins/CustomNuGet/Views/custom.cshtml already exists.
The output window shows things like this on Uninstall-Package CustomNuGet:
The item /Plugins/CustomNuGet/CSS/custom.css could not be found in your workspace.
The item /Plugins/CustomNuGet/Scripts/custom.js could not be found in your workspace.
The item /Plugins/CustomNuGet/Views/custom.cshtml could not be found in your workspace.
I have created a custom Nuget package using the command line tools. The folder looks like this:
/CustomNuGet
CustomNuGet.nuspec
CustomNuGet.0.1.1.nupkg
/content
/lib
CustomNuGet.dll
/Plugins
/Views
custom.cshtml
/Scripts
custom.js
/CSS
custom.css
The spec file was created using: nuget spec and the package nuget pack in the root CustomeNuGet folder per the documentation. Here is the spec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>CustomNuGet</id>
<version>0.1.1</version>
<authors>CustomNuGet</authors>
<owners>CustomNuGet</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>CustomNuGet</description>
<tags>CustomNuGet</tags>
<references>
<reference file="CustomNuGet.dll" />
</references>
<dependencies>
<dependency id="WebActivatorEx" version="2.0.0" />
</dependencies>
</metadata>
<files>
<file src="content\lib\CustomNuGet.dll" target="lib"/>
<file src="content\Plugins\**" target="content\Plugins" />
</files>
</package>
I didn't see any posts about this exact issue so hopefully others have had this happen and it's only a setting I missed.

This can happen if you deleted .dll reference manually instead of using uninstall-package to remove it through console. Check packages.config file, package you're trying to install is probably still listed there. You will have to delete it from that config file and save changes. After you did that, try installing package again and it should work.

Related

Create Visual Studio Custom Template containing .cshtml files and pack in Nuget Package

I'm trying to create a custom template in .NET Core 3.1 using Visual Studio 2019 by following the steps mentioned here. I have made the changes in the .csproj files as mentioned in the link. When I install the template by directly referencing the project folder, and create a project using that everything works fine and cshtml files are also created.
But when I try to install the template using nuget package .cshtml files are not included in project output. Can anyone tell me how to include .cshtml files in Nuget Package.
I'm using the below commands
To create nuget package --> dotnet pack --output nupkgs
To install custom template using nuget --> dotnet new -i <Path To Nuget Package>\testinmem.1.0.0.nupkg
To create project --> dotnet new testis4inmem -n qwerty --force
But when I try to install the template using nuget package .cshtml
files are not included in project output. Can anyone tell me how to
include .cshtml files in Nuget Package.
I think you can use nuget.exe cli with nuspec file.
1) first make sure that you have followed this guidance to config your environemnt and then you can call nuget.exe in CMD.
Use CMD to enter the project folder(which xxx.csproj file exists)
2) Type nuget spec to generate the xxx.nuspec file and modify like this:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</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>1</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>Tag1 Tag2</tags>
<contentFiles>
<files include="xxxxx\xxx.cshtml" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
<files>
<file src="xxxxx\xxx.cshtml" target="ContentFiles\any" />
<file src="xxxxx\xxx.cshtml" target="Content" />
</files>
</package>
3) Before typing nuget pack xxx.csproj to generate the nuget package, you should rebuild your project first.
Hope it could help you.

Nuget package creation - Class library that targets .NET framework 4.6.1 can not target correct framework

I created a class library that targets .net framework 4.6.1 (so pretty much a blank canvas, with a single method to return a string, just for testing purposes). I want to make this into a nuget package. I'm following this article https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework , but when I get to "nuget pack" I get the following warning:
"WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below:
- Add a dependency group for .NETFramework4.6.1 to the nuspec"
I tried adding the dependency group to the .nuspec file:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Author</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>H</description>
<copyright>Copyright 2019</copyright>
<tags>blah</tags>
<dependencies>
<group targetFramework=".NETFramework4.6.1" />
</dependencies>
</metadata>
</package>
and I also tried:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Author</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>H</description>
<copyright>Copyright 2019</copyright>
<tags>blah</tags>
<dependencies>
<group targetFramework="net461" />
</dependencies>
</metadata>
</package>
I still get same error.
I tried using older versions of nuget, where the warning message isn't shown, but the same problem persists (If I try to add via the package manager, it says it has no dependencies).
WARNING: NU5128: Some target frameworks declared in the dependencies
group of the nuspec and the lib/ref folder do not have exact matches
in the other location. Consult the list of actions below.
This is an open issue in Github/Nuget, see #8713. I can reproduce same issue in my VS2017 with Nuget V5.3, and this issue goes away if I use Nuget V5.2 or earlier. For this situation, I'm afraid you have to use earlier versions of Nuget.exe until the team releases the fix.
If I try to add via the package manager, it says it has no
dependencies
1.If it displays no package dependencies though your package project depends on some nuget packages, please check if you're using packageReference to manage nuget in your current project. For now, nuget pack command doesn't work well for .net framework projects with packageReference or new SDK format projects.
You can check details from Leo's answer to resolve this issue.
2.If the no dependencies you mean is that when one project consumes your package, it doesn't display which framework your project targets like this:
(We can see your package depends on Newtonsoft.Json but we can't find which framework it targets(net461).)
For this, we need to use command like nuget pack xx.nuspec to add the dependencies+group into package when packing. Then we can see both targets framework and dependent packages like this:
Hope all above helps and if I misunderstand anything, feel free to correct me :)

Nuget returned an unexpected status code '404 Not Found' - Package on local drive

Trying to generate a Nuget Package from dll. One of our project is generating ConfigurationCore.dll and References of project assemblies given below
Microsoft.CSharp
Newtonsoft.Json
Mak.Enums (Custom Nuget Package available on local Nuget Server)
Mak.Operations (Custom Nuget Package available on local Nuget Server)
PresentationCore, PresentationFramework, PresentationFramework.Aero
System, System.Core, System.Data, System.Data.DataSetExtensions
System.Drawing, System.IO.Compression, System.IO.Compression.FileSystem
System.Net.Http, System.Runtime.Serialization, System.Web
System.Xaml, System.Xml, System.Xml.Linq, WindowsBase
Using below ConfigurationCore.nuspec to generate Nuget Package
<?xml version="1.0"?>
<package >
<metadata>
<id>ConfigurationCore</id>
<version>1.2.0</version>
<title>Configuration Core</title>
<authors>MAKK</authors>
<owners>IT Department</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ConfigurationCore contains core funcationality of Software</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2018</copyright>
<dependencies>
<dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>
</metadata>
<files>
<file src="C:\Users\makk\source\repos\ConfigurationCore\bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
</files>
</package>
Attempting to gather dependency information for package 'ConfigurationCore.1.2.0' with respect to project 'NugetTest', targeting '.NETFramework,Version=v4.6.1'
Gathering dependency information took 1.09 sec
Attempting to resolve dependencies for package 'ConfigurationCore.1.2.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'ConfigurationCore.1.2.0'
Resolved actions to install package 'ConfigurationCore.1.2.0'
The V2 feed at 'http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'.
Time Elapsed: 00:00:02.1513344
========== Finished ==========
Note: The Nuget package source is on local harddrive... Please advise to fix the issue.
Update your Nuget package link.
Go to Project -> Manage Nuget Packages.
Now click on your package source settings.
Update Source Link to https://api.nuget.org/v3/index.json
Your URL should end with /nuget
Example:
http://yourDomain.co/yourNuGetServer/nuget
This is problem of bad connection in the NuGet package. Add the following link into the NuGet Package.
https://api.nuget.org/v3/index.json
Tha
Nuget returned an unexpected status code '404 Not Found' - Package on local drive
Make sure the path in the src="..." is correct.
Perhaps the path should be:
...\ConfigurationCore\ConfigurationCore\... rather than ...\ConfigurationCore\....
In short, make sure you can find the dll file base on that url.
Note: Generally, we recommend using relative paths in url, like:
<file src="bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
Update the version of nuget.exe.
There is an issue on the nuget.exe 3.4.x, so please download nuget.exe 3.5 and above.
See Create nuget package from dlls for more detailed info.
Update:
Please following below steps to create the nuget package:
Download the nuget.exe, and set it on your local, for example, D:\NuGetLocalFolder.
Create a new project with project name "ConfigurationCore".
Open a cmd and switch to the path where nuget.exe was stored previously.
Use command line:
nuget spec "C:\Users\<Username>\Source\repos\ConfigurationCore\ConfigurationCore\ConfigurationCore.csproj"
You will find the .nuspec be genererated, Do not close this CMD window.
Edit the ConfigurationCore.csproj.nuspec file and modify it, below is my .nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>ConfigurationCore</id>
<version>1.2.0</version>
<title>Configuration Core</title>
<authors>MAKK</authors>
<owners>IT Department</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ConfigurationCore contains core funcationality of Software</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2018</copyright>
<dependencies>
<dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>
</metadata>
<files>
<file src="C:\Users\Admin\Source\repos\ConfigurationCore\ConfigurationCore\bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
</files>
</package>
Save ConfigurationCore.csproj.nuspec file, and back to your CMD window, using pack command to generate the nuget package:
The package ConfigurationCore.1.2.0.nupkg was created into the folder where nuget.exe exists, D:\NuGetLocalFolder.
This can happen because you are supplying a "nuget v3" url when only a "nuget v2" url is supported (in my case apt-get was giving me some ancient version of nuget). Typically a nuget source that supports v3 will also support v2, so if your url looks like
https://<something>/api/v3/index.json
try changing it to
https://<something>/api/v2
This is because you are referencing a non existing link: http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0'
You are using a method inside url, which is invalid and is the cause for the mistake:
//this is an error
../nuget/FindPackagesById()?
fix the url, test it and try again,

NuGet: package with source code that can be referenced as library

Is there any possibility to create a NuGet package containing the source code that can be referenced as library?
When I use the .nuspec for packing the created .nupkg contains the source code but cannot be referenced. I have already tried out to add a library node within the .nuspec as some suggested on SO but the resulting .nuspec does not match the standard and thus cannot be created.
When using .csproj for packing the .nupkg does only contain the .dll. It can be referenced but cannot be debugged because it does not contain any source code.
How could I achieve both? A referanceable library that contains source code.
In advance thank you for your time.
Here's a .nuspec file I use to package sources from multiple directories that get used as a library in other projects:
<?xml version="1.0"?>
<package >
<metadata>
<id>Your.Package</id>
<version>1.0.14</version>
<authors>me</authors>
<owners>me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Class library.</description>
<releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>some tags</tags>
</metadata>
<files>
<file src="*.cs" target="content/App_Packages/<YourPackage>.Sources" />
<file src="Configuration/*.cs" target="content/App_Packages/<YourPackage>.Sources" />
</files>
</package>
Just change the "file" tags to reference the files you're trying to include.
When you're ready to create the .nupkg file, cd to the directory containing your .nuspec file and run:
nuget pack .nuspec
There's now the csproj tag EmbedAllSources. What that does is embed your source code into your NuGet package.
Usage is like this:
<EmbedAllSources>True</EmbedAllSources>
Embedding the source code will allow people to, for example, navigate to your method definitions and see the code just the way you've written it, as opposed to, not being able to navigate to definitions, at all, or rely on decompiled code.
Adding the debug symbols to the above will allow your users to put breakpoints in your code and step through it during debugging.
If that is what you want, add this to your csproj:
<DebugType>Embedded</DebugType>
<EmbedAllSources>True</EmbedAllSources>

Create nuget package for a solution with multiple projects

We are currently building a solution with several projects.
We have something like this:
- Common
- Logging
- Logging.NLog
- Threading
So Logging.NLog is dependant on Logging, Logging on Common...etc.
When we pack Logging.NLog I would like nuget to discover the Loggin and Common dependecies.
At the moment, I created a package with Common, then in Logging I installed the package Common with
install-package Common
But whenever I do a modification to Common, I have to update the package and they are created by our continous integration systeme (Hudson), so it is pretty annoying when we are developing.
I would like to simply have a Project Reference (Add References -> Project...) and the nuget discover the depencies anyway.
Is there a way to achieve it?
There is a planned feature targeting this exact scenario.
This is how it will apparently look like:
> nuget.exe pack proj.csproj -IncludeReferencedProjects
It has apparently been implemented mere days ago, but there are bugs still being ironed out.
The feature, as it currently stands, allows:
packaging several projects' artifacts into a single nuget package (by walking project references recursively),
OR
creating nuget package references to those projects's associated packages, if the referenced projects have accompanying .nuspec files.
The feature request dates back all the way to 1.5, but it kept slipping. Recently though, it gathered enough mass (requests) to be scheduled for release in Nuget 2.3.
The release plan pegs version 2.3 for "End of April, 2013" so stay tuned.
(Presently, the latest Nuget version is 2.2.1).
There is currently no way to do exactly what you ask, but the following will help you streamline your updates.
It sounds like you need to add nuspec files to your solution. Something like the following three files. Note the dependencies in the second two. These refer to the same dll version as common through [$version$]. This means that when you run the following command, it updates all three because the square brackets on the dependencies require a specific version of the dependent packages.
PM> update-package common
In Hudson, you will need to execute these nuspec files using nuget pack command (see Nuget command reference) and include the resulting packages in your artifacts, AND deploy them to your local nuget server. I will leave that over to you.
The other thing you would need to do is ensure that all of your assemblies get the same version for the same build. Again, Hudson can take care of this or you could use a common AssemblyInfo file.
Common.nuspec
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<version>$version$</version>
<authors>Charles Ouellet</authors>
<owners />
<iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
<id>Common</id>
<title>Common</title>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>full description here</description>
</metadata>
<files>
<file src="..\Common\bin\Release\Common.dll" target="lib\net40" />
<file src="..\Common\bin\Release\Common.pdb" target="lib\net40" />
</files>
</package>
Logging.nuspec
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<version>$version$</version>
<authors>Charles Ouellet</authors>
<owners />
<iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
<id>Logging</id>
<title>Logging</title>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>full description here</description>
<dependencies>
<dependency id="Common" version="[$version$]" />
</dependencies>
</metadata>
<files>
<file src="..\Logging\bin\Release\Logging.dll" target="lib\net40" />
<file src="..\Logging\bin\Release\Logging.pdb" target="lib\net40" />
</files>
</package>
Logging.NLog
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<version>$version$</version>
<authors>Charles Ouellet</authors>
<owners />
<iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
<id>Logging.NLog</id>
<title>Logging.NLog</title>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>full description here</description>
<dependencies>
<dependency id="Logging" version="[$version$]" />
</dependencies>
</metadata>
<files>
<file src="..\Logging.NLog\bin\Release\Logging.NLog.dll" target="lib\net40" />
<file src="..\Logging.NLog\bin\Release\Logging.NLog.pdb" target="lib\net40" />
</files>
</package>
I think Charles means he wants NuGet to automatically resolve project references into package dependencies if said referenced projects also are used to construct NuGet packages, right?
Example:
Logging is set up to generate a NuGet package
Logging.Nlog is set up to generate a NuGet package
Logging.Nlog has a project reference to Logging.
The generated Logging.Nlog package should get a dependency on the generated Logging package.
This is something I had been looking for myself as well, but sadly I found that it is currently not supported. There is a work item on it, scheduled for NuGet 1.7, but there isn't even a design on how to handle this yet.
This thread has a good suggestion: NuGet and multiple solutions
Basically, break out the common components to their own Solution, with their own release lifecycle.
I managed this achieve it like this:
<ProjectReference Include="MyProject2.csproj" PrivateAssets="All" />
Add PrivateAssets="All" in MyProject.csproj for each project.

Categories