I'm having trouble of dependencies in a chain of NuGet projects (Visual Studio 2019 and NuGet 5.7.0.6726).
The first project, include Log4Net NuGet package from NuGet.org, I package it with "nuget.exe pack mx_logging.vbproj -IncludeReferencedProjects" and I have my own (MX_Logging.nupkg).
A second Project use MX_Logging and i got the installation of Log4Net too, no problem so far...
Now, if i pack the second project too with the same method used before, it only have MX_Logging and not log4net as dependencies, how my i fix this?
This is the package.config in the second project root:
<packages>
<package id="log4net" version="2.0.8" targetFramework="net452" />
<package id="MX_logging" version="1.2.7668.29513" targetFramework="net452" />
</packages>
Thanks a lot to everyone ;-)
In my side, when I installed the second nuget project into a new net framework 4.5.2 project, it has the log4net nuget dependency.
log is the first nuget project and log1 is the second nuget project.
So please try the following steps:
1) delete bin and obj folder of the second nuget project.
2) clean nuget caches first or delete all cache files under C:\Users\xxx\.nuget\packages
3) rebuild your second nuget project and then
cd xxx\xxx\the second project folder(where exists the csproj file)
nuget spec
nuget pack xxx\xxx.csproj -IncludeReferencedProjects
4) make sure the second nuget package and the first nuget package are all under the nuget package source.
Update
I used nuget.exe cli v5.6.0 to pack the nuget project and I also test with v5.7.0. All are right.
Actually, I am guessing if you just see the second nuget package UI which does not list log4net nuget dependency.
Although it does not list log4net, but the log4net nuget dependency is under log nuget package. When you install log1 nuget package, it will install log nuget dependency with its log4net nuget dependency. And it just does not show the dependencies of the inter-generation package. But the log4net nuget package really exists. Just as my first pic shows.
But if you still want to the dependency shown on the UI, or your nuget package really has some problems, you could try this:
modify the second nuget project's nuspec file and add these:
<dependencies>
<dependency id="log4net" version="2.0.8" />
</dependencies>
The whole nuspec is like these:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>1og1</id>
<version>1.0.0</version>
<title>me</title>
..........
<tags>Tag1 Tag2</tags>
<dependencies>
<dependency id="log4net" version="2.0.8" />
</dependencies>
</metadata>
</package>
Then, repack your second nuget project.
Related
I generate a nuget package using my nuspec file below:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>CommonLib</id>
<version>1.2.3</version>
<authors>ABC</authors>
<owners>ULC</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">Licenses\License.txt</license>
<icon>Icons\Icon.PNG</icon>
<description>Common References</description>
<copyright>Copyright (c) 2020</copyright>
<tags>Common</tags>
<dependencies>
<group targetFramework="net48" />
</dependencies>
</metadata>
<files>
<file src="lib\net48\Common*.dll" target="lib/net48" />
<file src="Licenses\License.txt" target="Licenses\" />
<file src="Icons\Icon.PNG" target="Icons\" />
</files>
</package>
The folder structure for the source data for packing is as the following:
RootDir
Icons
Icon.png
lib
net48
Abc.dll
Common1.dll
Common2.dll
xyz.dll
Licenses
License.txt
My.nuspec
I successfully generate it. However, whether I host it locally or in my Azure Artifacts as private feed, then when I browse in VS2017 (that's what I currently have installed) to install for a project then the generated package doesn't show its embedded icon, instead, it shows the default nuget pack icon. I tried browsing either from my local feed or from Azure private feed, same thing. What's the reason my embedded into nuget pack icon is not being used?
Embedded into NuGet package icon doesn't appear in VS
Actually, this is a well-known issue for nuget and for creating our own nuget feed, package source, or local address, the nuget icon cannot be displayed in the package manage UI. See this similar issue.
So if you add comments in this github link to get the staff's attention so that they can focus on the issue and fix it.
In your situation, you use private local nuget feed to install such nuget package and it cannot be realized and the latest version nuget.exe v5.5.1 does not support this so far.
Solution
Please upload your nuget package into nuget.org website an then use nuget.org nuget feed to install your nuget package.
And nuget.org supports the sustom icon to show your nuget package.
And then you can directly use nuget.org to install your own nuget package.
l have test it:
local feed:
nuget.org website:
Besides, you could suggest this feature in Our User Voice Forum to reflect your thoughts
I have a Visual Studio project file with the extension .csproj. Inside it are references like this:
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props"....
I have now made a NuGet.config file in the parent folder of from the solution folder. And I removed the local "packages" folder. In the new nuget.config I set up a common location for storing packages.
nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="D:\Data\NuGet" />
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
</configuration>
When I building I now get this error:
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information...
The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.
How can I solve this?
If I manually have to replace the (Import Project="..\packages...) elements in the project file, what should I change it to, so that it follows the configuration from the Nuget.config?
If I manually have to replace the (Import Project="..\packages...)
elements in the project file, what should I change it to, so that it
follows the configuration from the Nuget.config?
Since you use the new nuget.config file which changed the path of the local nuget reference(like this <add key="repositoryPath" value="xxxxxx" />).
And Restore will only restore the missing nuget packages but will not change to use the new nuget package location in xxx.csproj.
So you can follow my steps to resolve the issue:
Solution
1) Tools-->Nuget Package Manager-->Package Manager Console-->
type Update-Package -reinstall to reinstall these packages to reference the new right path.
2) enter the xxxx.csproj file, delete these duplicate, old import info like these:
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\..\..\..\..\installed_packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
3) Then rebuild your project and will solve this issue.
Update 1
The new Nuget.config file will specify that the newly installed nuget packages use the new reference address, but for previously installed nuget packages, the reference address in the xxx.csporj file will remain the old address. The Restore procedure only restores the nuget package under the new path, but it does not make any changes to the nuget reference in xxx.csproj file, so it can only be reinstalled.
Besides, the import node is created by Microsoft.Net.Compilers props file from the build folder in the microsoft.net.compilersnuget package. And it is a nuget mechanism which can do some operation in xxx.csproj file when you install the nuget package.
However, this file is also special and when you change the nuget reference path.
Because nuget enabled the new address mechanism, during the uninstallation process, the old address of Microsoft.Net.Compilers.props is still not recognized, so it cannot be uninstalled. In fact, when you execute the reinstall nuget package, a new address has been created in the xxx.csproj file. See this:
So you should just delete duplicate files from the old address.
Visual Studio option to change the Nuget Package References
In Visual Studio Tools=> Nuget Package Manager => Package Sources.
You can change the package sources here.
I have a PCL library I want to distribute as NuGet package.
Screenshot of the PCL application library properties page:
csproj file:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Steps to reproduce my problem:
Clone both repos from:
NuGet package
Console application + PCL library
Build the NugetPackage project + nuget spec + nuget pack
Create a local nuget package repository pointing to the project folder.
Open the NugetConsole solution and try installing the package in both projects.
Some references I used:
https://learn.microsoft.com/en-us/nuget/schema/target-frameworks
https://learn.microsoft.com/en-us/nuget/schema/nuspec
https://portablelibraryprofiles.stephencleary.com/
http://blog.stephencleary.com/2012/05/framework-profiles-in-net.html
How can I make a nuget package from a PCL library and use it in a PCL library?
I have downloaded your nuget package and test projects, I can created the nuget package and installed it to the both projects. Following are my detailed steps:
1. Create nuget package:
Download the nuget project, then build the project+nuget spec+nuget pack:
Here is the .nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>My.Package</id>
<version>1.0.0</version>
<authors>Tester</authors>
<owners>Tester</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="bin\**" target="lib\portable-net45+wp8\" />
</files>
</package>
Note: Since you are planning use this package into PCL library, so the target should be .net45 + Profile49, according to the document Portable Class Library (PCL) profiles, nuget target should be portable-net45+wp8:
2. Install that package to both projects:
Download those two test projects from GitHub, and open it with Visual Studio 2017, then copy the created package to the local nuget feed:
Open Package manager Console, install the package with following command:
install-package My.Package -source D:\LocalServer
So the nuget package is correct install in both projects.
Note: I have seen following code in your project file of console application:
<ItemGroup>
<PackageReference Include="My.Package">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
Please remove it, this is not a correct way to add nuget package.
My organization wants to segregate all the development machines on a network without internet access.
I found this article that gives that gives some nuget host product, so that the packages are available offline.
My problem is that I can't find a way to manage the package update, because the machines that have and internet access won't have Visual studio installed.
I was looking if there is a tool that reads a folder where all nupkg files are stored and check if a newer version is available and downloads it, or otherwise reads a manually created packages.config file checks for newer version and download them on a folder.
Does anyone have an idea how to manage nuget packages in this way? I spent the last week trying to find a way but I had no look.
Does anyone have an idea how to manage nuget packages in this way?
According to the NuGet CLI reference:
The update command also updates assembly references in the project
file, provided those references already exist.
So when we use NuGet.exe update the package, we are not only need the packages.config but also need the solution/project, otherwise, you will get the error:
"Unable to locate project file for 'D:\NuGetServer\packages.config'
You can copy a simple project from the machine, which have Visual Studio installed, then use below command line to update the nuget package in the package.config file:
nuget update "YourProjectPath\packages.config"
But NuGet will update the packages into the packages folder under the solution folder by default, so we need change the packages folder to the folder where all nupkg files are stored before update packages.
Detail steps:
Download the nuget.exe from nuget.org, set it to your local machines.
Create a NuGet folder under the path %appdata%, add the NuGet.Config file and change the packages folder by repositoryPath, just set it "D:\NuGetServer":
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<config>
<add key="repositoryPath" value="D:\NuGetServer" />
</config>
</configuration>
Copy a solution from other machine, add the packages in to the package.config file:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NUnit" version="3.7.0" targetFramework="net45" />
</packages>
Open a CMD file, switch to the path where NuGet is stored in step 1, then use the update command:
You will find packages in the packages.config are updated to the latest version.
I am trying to automate the process of installing nuget packages into new visual studio projects. My idea is to reduce the time it takes to source all the packages via the nuget package manager, by specifying the packages in a custom file that can be run to install these packages. Therefore only requiring every new project to include this file and running it each time. I'm very new to nuget and have been assigned this task without much prior knowledge. I was advised that .nuspec route would lead me in the right direction, since it contains the meta data about a package. Although since consumers don't have direct access to the .nuspec file of a package, I am failing to understand how it can be used as part of this automation. I have also heard about automatic package restore, but since that only works for lost reference, I don't see how it will help in new projects that haven't necessarily referenced anything to do with that project.
note that you cannot simply drop a pre-built packages.config file into a new project and expect it to work. When installing, NuGet modifies the project file (.csproj) to include references and uses packages.config for downloading missing files (and update/conflict logic).
Using VS 2017 (released stable versions 15.2 and higher) and the PackageReference style of referencing projects, you can simply drop a Directory.Build.props file into the root of your solution containing all the projects you need:
<Project>
<ItemGroup>
<PackageReference Include="Autofac" Version="3.5.2 />
<PackageReference Include="Topshelf" Version="3.2.0 />
</ItemGroup>
</Project>
This will add these NuGet packages to all new projects in the solution without the need for the .csproj files to be modified. (note that after adding/editing this file, you need to close and re-open the solution. this should be fixed in the upcoming VS 2017 15.3 update for editing the file).
Nuget already supports automation of installation and we can use nuget commandline to achieve this
Everytime you add a nuget package in Visual Studio,it gets add to a file called packages.config file.
E.g. will look like this
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net451" />
<package id="Microsoft.Owin" version="3.1.0" targetFramework="net452" />
<package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Hosting" version="3.1.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
<package id="Owin" version="1.0" targetFramework="net451" />
<package id="Topshelf" version="3.2.0" targetFramework="net451" />
</packages>
Every project you have in your solution will have packages.config file. You can go to the parent folder of all the projects and simply run comand 'nuget restore', it will get all the packages for you.
For this to work, nuget.exe needs to be downloaded separately .More details on the nuget command line can be found here and here's the commandline reference
Edit:
Thanks #Martin Ullrich pointing out.Just to be clear, The above method will not add the references to project file automatically,it will only get the packages to the packages folder.In VS2017,the support is there which #Martin's answer addresses.
Hope this helps!