I have a .net resource library which contains some nuget packages as well as some default .net references:
NLog (nuget)
Microsoft.Expression.Drawing (.net reference)
System.Windows.Interactivity (.net reference)
If I build my nuget package
nuget pack -Prop Configuration=Release -OutputDirectory nuget %SOLUTION%\%SOLUTION%\%SOLUTION%.csproj
and install it afterwards in a wpf project, the two .net references where not installed.
Is there a solution to automatically install the .net references?
As bradbury mentioned, I haved created a *.nuspec file and added all framework assemblies into it.
To automatically add these items to the nuspec without thinking about it, I have extended my personal nugetLib with a new function.
Now I have just a 1 liner in my ci script:
# add framework assembly dependencies into the nuspec file
- nugetlib frameworkassemblies -c %SOLUTION%\%SOLUTION%\%SOLUTION%.csproj -n %SOLUTION%\%SOLUTION%\%SOLUTION%.nuspec -p %SOLUTION%\%SOLUTION%\packages.config
Source: https://github.com/dojo90/nugetLib
Related
I want to list down all the nuget packages along with its dependencies recursively.
Project is in VS2017 and .NET Core.
I tried with Get-Package -ProjectName "Your.Project.Name" it displays all the nuget packages in project. I want all the dependencies also printed.
You can use the dotnet cli: dotnet list package --include-transitive. The dotnet-outdated global tool probably has similar functionality.
I am having c# .net core project. Project name is Master and it has dependencies of external NuGet package as "SpecFlow.CustomPlugin". Master project has Two classes as Shape.cs and Factory.cs.
When I generate the NuGet package of Master project so that the implementation of Shape.cs and Factory.cs class can be useful as library into other projects. After generating the NuGet package of Master project I only see the "SpecFlow.CustomPlugin" content with it's own dependent dll files but I am not able to see dll of Master project in newly generated NuGet package.
Newly generated NuGet package is included in another project let's say Consumer. Consumer want to use the Shape.cs method and Factory.cs method but it's not accessible.
Master project Dependencies looks like:
First, make sure that Shape and Factory are public. If you don't specify their visibility, they're private by default, which means that they can not be used directly by other projects, either as package reference or project references.
When you pack master into a NuGet package, the default file it will create is bin\Debug\master.1.0.0.nupkg. Assuming master is targetting .NET Standard 2.0, master's dll is saved as lib\netstandard20\master.dll in the nupkg. You need add/push this nupkg to a nuget feed (can be a directory on your computer or network, nuget.org or you can host your own feed). Your comsumer project will need a nuget.config that adds the correct NuGet feed as a source, then you add a package reference to the master package. After you restore (which Visual Studio does automatically if you added the package with the UI), then you can use any of master's public classes.
Here's commands you can run on the command line to set up two projects, one is a package, the other will consume it. If you're using .NET Core in Visual Studio, it must have already downloaded the .NET Core SDK, which puts the dotnet cli on your path. You'll also need to download nuget.exe from https://www.nuget.org/downloads/.
dotnet new nugetconfig
nuget source -configfile nuget.config add -name local -source feed
# create an isolated nuget environment, because I don't like to populate
# my global packages folder with test packages
nuget config -configfile nuget.config -set globalPackagesFolder=gpf
# create a library, pack it, and add the nupkg to our local feed
dotnet new classlib -n MyLib
dotnet pack MyLib\MyLib.csproj -o nupkgs\
nuget add MyLib\bin\Debug\MyLib.1.0.0.nupkg -s local
# create console app and reference MyLib
dotnet new console -n MyApp
dotnet add MyApp\MyApp.csproj package MyLib --version 1.0.0
#if you want to open these projects in Visual Studio
dotnet new sln -n sample
dotnet sln add MyLib\MyLib.csproj
dotnet sln add MyApp\MyApp.csproj
start sample.sln
Normally you wouldn't use a NuGet package to use one project from another project in the same solution. Just make them project references, and when you pack a project into a NuGet package, the project reference becomes a NuGet dependency. I only did it this way to demonstrate how to easily consume a package that you created yourself.
All .NET framework projects that use Nuget have a packages.config per project. When I run something like:
nuget update MySolution.sln -Id PackageName -Version 1.2.3
It will update all projects in my solution that use this package to the specified version (1.2.3 in this case)
However, I'm finding that this does NOT work for UWP projects. UWP does not use packages.config and instead put the package references directly into the csproj file. As a result, this is literally what nuget update says when I run it:
Found 2 projects with a packages.config file. (A.csproj, B.csproj)
where A and B are my .NET Framework projects that still have a packages.config file. But this list doesn't include my new UWP projects.
Is there another command for nuget update that will work with UWP projects?
How do I update UWP projects' nuget packages via the CLI?
This is a known issue for the packagereference. At the moment, NuGet CLI does not support automatic package updates to the the new .NET Core .csproj format, you can refer to the below GitHub issue for details:
support for updating references into csproj from commandline(s)
Besides, as test, the workaround using following command line does not work with UWP project
dotnet add package <PackageName> --version <version>
Indeed, currently it is very inconvenient to manage packages outside of Visual Studio for UWP with packagereference.
Hope this helps.
Currently I have a requirement where we have separate assemblies for contract and implementation. After creating a nuget package and attempting to consume nuget package, it fails because Package manager is unable to find dependent (contract) assembly.
This seems to be an open issue in .net core.
https://github.com/dotnet/cli/issues/3959
Unable to understand why such simple thing will not work in .net core. Looking for workaround for this issue.
It is simple to solve. You have 2 options:
A) Pack and Publish all your projects as Nuget packages:
You just add your dependencies as ProjectReference into your main projects. And continue development using project references. Also must pack all dependency projects as well. When you want to publish your packages using the same version just run:
dotnet pack -p:PackageVersion=2.1.0 also can add any other pack arguments.
Since during pack all ProjectReference will be transformed to Package dependencies. And version number is cascading into all package.
In this case your original main project and all of its dependencies will be Nuget packaged. Now you have to publish ALL. And when you want to install your Nuget package it will install all of its dependencies as well with the same version specified.
B) Package all output DLLs into a single Nuget package:
You can Publish only one Project as Nuget package and pack all other DLL into that package. First suppress pack to transform dependency from Project to Package. Find your ProjectReference and add PrivateAssets="All" to it. Should look like this:
<ProjectReference Include="yourproj.csproj" PrivateAssets="All" />
And add the following section to your .csproj file (to the project which should be packaged) to package dependency DLLs, change the DLL name and Framework version in <PackagePath>.
<ItemGroup>
<_PackageFiles Include="$(OutputPath)\yourproj.dll">
<BuildAction>None</BuildAction>
<PackagePath>lib\net5.0</PackagePath>
</_PackageFiles>
</ItemGroup>
After reading documentation I understood .net core discourages project reference instead advises to use package reference. This is mentioned in description heading in following doc.
https://github.com/dotnet/docs/blob/master/docs/core/tools/dotnet-pack.md
I published my contract assembly to nuget package and consumed it in implementation as nuget package.
I'm Nuget packaging with CreateNewNugetPackageWithEachBuild.
Nuget auto installs dependencies another Nuget packages. It works.
But this is not work in Framework libraries like the System.Drawing namespace, UIAutomationTypes assemblies etc.
So when I install my Nuget package, after install that -> and goto "add reference" menu and add framework assemblies manually (System.Security or something, not yet added another DLLs when create project time).
Can I make Nuget pakcages to auto-include the .Net Framework level assemblies when install it?
Make .nuspec file in project folder (be with .csproj file) and define frameworkAssemblies in nuspec file and build it to makes nupkg contains framework level assemblies and auto include when install it