I have a C# project that uses Nuget for package management. I enabled package restore so it created the .nuget folder. Then I want to create a Nuget package of this project. Can I create nuget .nuspec files in the .nuget folder and modify the Nuget.targets file to allow the creation of the package and upload to the galery when I'm in release mode?
Thanks.
You can do that.
Alternatively you can use nuget.exe pack command in the post build event ( more details # http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command )
or use true in the csproj file.
Related
When I used vs2015, packages were added to a packages folder in my solution and a package.config file was added and also reference includes in the csproj file. But since I use vs2017 I'm not able to install or update any nuget packages, although the packages are downloaded and unzipped in this location:
C:\Users\user.nuget\packages:
packages
I tried both Manage Nuget Packages and Package Manager Console, but I get the errors "Install failed. Rolling back." and "Could not add reference, dll not registered." I tried installing webview2, newtonsoft json and restsharp but get the same errors.
Here's the output:
output packetmanager
So how can I download and unzip a package into a package folder in my solution and install it in my project ?
I am trying to create a nuget package from .net6 project xml file. I have added README.md into the project file. When I install the package in another project, I want the README file to be copied to the output directory. Since I m working with pipelines, I am directly creating packages from project file without separately creating nuspec file. Is there a way to add some property in the project file which enables copying readme files upon installation of package?
I am using Visual Studio 2017 and pull the source code from TFS server, then build the solution, I got the following error:
Microsoft.Common.CurrentVersion.targets (3863,5): Error MSB3113: The
file "SqlServerTypes \ x64 \ SqlServerSpatial140.dll" was not found.
Then I found this dll file comes from the nuget package sqlserver.types, as I know, Visual Studio will restore the nuget packages when we build the solution.
Why I still have this issue?
File was not found after nuget restore
When you download the nuget package Microsoft.SqlServer.Types from the nuget.org and open it with nuget package explorer:
You will find the sqlserver.types nuget package not only includes .dll from .net framework, but also has native binaries files. These files are designed with x64 and x84, they could not added to lib folder directly. So the package owner adds them to project as content. However, these dll files is setting to ignore by default for TFS, you need to add them manually.
Of course, you can also use the command line Update-Package <package_name> –reinstall to reinstall this nuget package, but this requires you to execute this command every time after you pull the code from the TFS server. Add this native binaries to the source control will Will reduce these unnecessary troubles.
Hope this helps.
You can try this:
Update-Package <package_name> –reinstall
When I run a command like nuget install pdfsharp to add an external library to the project, the library is installed but as mentioned in the nuget documentation the command does not modify the project or packages.config.
Since I'm adding to an empty hello world, how do I create this packages.config file for nuget to later use nuget restore? I'm not finding in the documentation the format of this file.
nuget install Will add the package but will not modify the project or xml config, See - https://docs.nuget.org/ndocs/tools/nuget.exe-cli-reference
Installs a package into the current project but does not modify the project or packages.config.
Try using the powershell commandlets, See - https://docs.nuget.org/ndocs/tools/powershell-reference#install-package
Install-Package pdfsharp
For a github hosted open sourced C# project which is also available via NuGet, how should one organize the source? Specifically:
should the .nuspec file be in the github repository?
should the .nuspec file be in the same folder as the .csproj file?
how about the NuGet package tree (the /lib, /content stuff), since is generated, should it be in git?
My thinking is that the NuGet part is separate from the github hosting, as in the project source are available but the .nuspec is not, since the publishing in NuGet is not an open source operation per-se. None wants that every fork to build and publish a new NuGet package, so that the open source Foo package ends up in the gallery as 'Rick's Foo' vs. 'John's Foo' vs. 'Alice's Foo' etc.
But on the other hand I do want the github source depot to act as a one-stop repository for the project, if I open my other laptop and enlist from there, I should be able to build/package/push w/o recreating the whole NuGet infrastructure from scratch (ie. only enter my API key, nothing more).
These two requirements are contradicting each other, Did I miss something obvious?
I would do the following:
Commit the .nuspec file next to the .csproj file
Add a nuget.config file which moves the packages folder a level up.
Enable package restore in the solution and do NOT commit the content of the NuGet package repository
Create an msbuild file (or whatever build vehicle you like) which has:
a "build" target which builds the source and creates the nuget package
a "publish" target which pushes the NuGet package to nuget.org and takes your API key as a parameter.
I personally maintain the version number of the nuget package in the .nuspec file and manually update it when I do a "release". This way I can tag the exact release I pushed to the NuGet feed.
With this setup a build in Visual Studio does not produce a NuGet package but all tools are available in the repository to do so.
The Folder Structure looks like this:
.\Docs\ ==> not in source repo
.\Packages\ ==> not under source control
.\Src\ ==> git repo here
.\Src\MySolution.sln
.\Src\.gitignore
.\Src\MuRules.ruleset
.\Src\build.proj ==> msbuild file to build everything.
.\Src\MyProject\MyProject.csproj
.\Src\MyProject\MyProject.nuspec
.\Src\MyProject\nuget.config
.\Build\ ==> not under source control
.\Build\Debug\
.\Build\Release\
.\Build\Publish\
Be aware of this bug in the Package Restore feature, it will ignore the packages location you configured. http://nuget.codeplex.com/workitem/1990 ==> This is fixed in Nuget 2.7
On nuget v2.8, I just need to modify .gitignore and add:
packages/
This will exclude the nuget packages folder from committing. When you build the new checked-out source code, the packages would be downloaded and restored. Make sure package restore setting has been enabled but I think it's been enabled by default on v2.8.