I have a nuget package that consumed by internal teams.
This is the dependency section in the nuspec file
<dependencies>
<dependency id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="5.2.9" />
<dependency id="Newtonsoft.Json" version="12.0.2" />
<dependency id="System.Runtime.Caching" version="4.5.0" />
<dependency id="Polly" version="7.1.0" />
</dependencies>
When some teams installed my nuget package, they complained that some dlls were downgraded. For example:
and
Yes, the code does use newton. However, in my dependency section, I didn't hard code the exact version and from visual studio, it shows this and I think newton json version 13 should be bigger than 12.0.2?
Then for System.Memory, I didn't include that as a dependency, so how come its version got degraded?
Related
There are several analyzers whose NuGet packages I almost always include in any project I make. It's annoying adding them all individually whenever I start a new project, so I have long wanted to make a NuGet package of my own that just says "include these other packages". I recently did so, and it seems to work fine. I made the following nuspec file, did a "nuget pack" and then a "nuget push" to a private package server:
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Rwv37.Metapackage.Analyzers</id>
<version>1.0.0</version>
<authors>Robert William Vesterman</authors>
<owners>Robert William Vesterman</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A collection of frequently used analyzers.</description>
<copyright>Copyright 2019 Robert William Vesterman</copyright>
<developmentDependency>true</developmentDependency>
<dependencies>
<group targetFramework="netstandard2.0">
<dependency id="CSharpGuidelinesAnalyzer" version="3.1.0" />
<dependency id="IDisposableAnalyzers" version="2.1.2" />
<dependency id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.4" />
<dependency id="StyleCop.Analyzers" version="1.1.118" />
</group>
</dependencies>
</metadata>
</package>
I then decided to do the same thing with a bunch of test-related packages that I almost always include in all of my unit test projects:
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Rwv37.Metapackage.UnitTesting</id>
<version>1.0.0</version>
<authors>Robert William Vesterman</authors>
<owners>Robert William Vesterman</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A collection of frequently used unit testing stuff.</description>
<copyright>Copyright 2019 Robert William Vesterman</copyright>
<developmentDependency>true</developmentDependency>
<dependencies>
<group targetFramework="netstandard2.0">
<dependency id="FluentAssertions" version="5.7.0" />
<dependency id="FluentAssertions.Analyzers" version="0.11.4" />
<dependency id="Moq" version="4.12.0" />
<dependency id="Moq.Analyzers" version="0.0.7" />
<dependency id="xunit" version="2.4.1" />
<dependency id="xunit.analyzers" version="0.10.0" />
</group>
</dependencies>
</metadata>
</package>
That did not work. When I add this metapackage to a unit testing project, I can see it (and its constituent packages) in VS 2019's Solution Explorer, but I get a bunch of errors saying things like:
The type or namespace name 'FluentAssertions' could not be found (are you missing a using directive or an assembly reference?)
I thought maybe I was misunderstanding the "developmentDependency" tag, so I removed that and bumped the version number, but this did not help.
What am I doing wrong? How do I do it correctly? Thanks.
Answering my own question:
It seems like it is due to some Visual Studio caching wackiness or something like that. As I noted in the original post, after I found that it didn't work, I removed the "developmentDependency" tag and bumped the version number, which did not help.
However, the way that I had upgraded the project to use the new version was via "Update" in VS's NuGet Package Manager. Just now, I instead tried uninstalling the old version, then installing the new version. It magically started working.
I tried each way a few more times, and it always was the same: If I "Update" version 1 to version 2, it doesn't work, but if I "Uninstall" version 1 and then "Install" version 2, it works fine. 🙄
Just for the sake of completeness, I will also mention that prior to discovering this workaround, I had tried various things like clean/rebuild, unload project/reload project, close VS/open VS, and combinations thereof (like clean/close/open/rebuild), none of which helped.
I wrote a NuGet package that when my other projects use it they get an old version of one of my DLLs.
I include the newest version of my DLL as a reference in my NuGet project.
Project1.nuspec:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>CommonLibrary</id>
<version>0.0.1</version>
<authors>It's Me</authors>
<owners>My Company/owners>
<description>Shared Library for Common Code and Wrapper</description>
<dependencies>
<dependency id="NLog" version="4.5.7" />
</dependencies>
</metadata>
<files>
<file src="CommonLibrary.dll" target="lib\net471" />
<file src="HelperCode.dll" target="lib\net471" />
</files>
</package>
The CommonLibrary.dll (the project) my NuGet package delivers the correct latest DLL, but that HelperCode.dll is always an older version.
in my project, I created a directory named: "binaries" and in that directory is the latest version of HelperCode.DLL. I reference that latest version in my project. So the NuGet package should deliver the latest version. I gave it a property of "Copy Local Always"
Any suggestions would be greatly appreciated.
I'm trying to create a custom nuget package out of one of my projects. When I try to install it into the test project that references it, I receive this error:
Package "package" 1.0.5 is not compatible with uap10.0.15063 (UAP,Version=v10.0.15063). Package "package" 1.0.5 supports: net (.NETFramework,Version=v0.0)
This obviously isn't the case because the test project can run fine referencing the Project itself.
I'm building the nuget package based on my nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>Project</id>
<version>1.0.0</version>
<title>Project</title>
<authors>company</authors>
<owners>company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>desc</description>
<copyright>cp</copyright>
<dependencies>
<group targetFramework="uap ">
<dependency id="Logging" version="1.0.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.NETCore" version="5.0.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.NETCore.Portable.Compatibility" version="1.0.0" exclude="Build,Analyzers" />
<dependency id="NuGet.Build" version="2.12.0" exclude="Build,Analyzers" />
<dependency id="NuGet.CommandLine" version="4.1.0" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\Release\*.dll" target="lib" />
</files>
"Logging" is also a custom nuget package I created from the .csproj file of another project.
I've tried removing the tag, and also tried renaming the targetFramework="uap", none of that works.
What could be wrong and what can I try to get this working?
The target doesn't just rely on the NuSpec file, it would depend on the C# project and the dll itself. Go to:
Project> Rightclick> Properties> TargetFramework>
Set it to .Net or whatever. Also, change your output type to a console application rather than a windows application, if that is doable.
Also, you should create the nuspec file using:
Nuget spec < ProjectPath >
This gives us the advantage to just change the metadata for .csproj files, and copies that into the package metadata automatically.
I'm not a 100% sure if this will fix it, but this should be what needs to be done. Best of luck!
I have created a package for a framework which depends on numerous projects within a single solution. I want to create nuget packages for the framework and various projects within the solution.
In Framework.Framework.nuspec, I have the following dependencies declared:
<dependencies>
<group>
<dependency id="Framework.CompositionRoot" version="1.0" />
<dependency id="Framework.Services" version="1.0" />
<dependency id="Framework.Domain" version="1.0" />
</group>
</dependencies>
And in each project file has its own nuspec file, such as Framework.CompositionRoot.nuspec, which has the following dependencies:
<dependencies>
<group>
<dependency id="Super.Services" version="1.0" />
<dependency id="Super.Data" version="1.0" />
<dependency id="Super.Domain" version="1.0" />
</group>
</dependencies>
My problem is that when I install Framework.Framework in another project, it seems to install some of the dependent nuget packages but not others. In this case, it installs Framework.CompositionRoot and Framework.Services, but not Framework.Domain.
Framework.Domain has its own nuspec file in the solution and the generated Framework.Framework.nupkg file shows Framework.Domain as a dependency. I have only installed Framework.Framework in the project, not Framework.Domain, since to my understanding this should be installed when I install Framework.Framework.
When I look in the references for the solution, it has added a Framework.Domain.dll, but half of the interfaces declared in that domain are missing. (I have made sure the missing interfaces are declared as public.) However, if I copy/paste the dll into the lib folder and reference it manually, all the of the interfaces are there.
Any help would be appreciated.
This was due to nuget installing old versions by default. While Framework.Domain was not in the list of installed packages when viewing through the package manager, it was visible in packages.config, and had an old version which did not contain the interfaces. (Nuget install will install the lowest version of dependencies by default.)
In order to fix this, I uninstalled the package and re-installed it using the flag:
-DependencyVersion "HighestPatch".
I have a requirement where I need to install configuration files into the target project via NuGet. These files are meant to be edited by the end user and should therefore NEVER be updated.
I tried splitting the configuration files into their own NuGet package and using NuGet's versioning constraints to solve this, but it doesn't work. There is no way to constrain it so upgraders never get a new version AND new installers get the latest version. For example:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Other Stuff Omitted -->
<dependencies>
<group targetFramework="net35">
<dependency id="MyPackage.MVC4.Core" version="[$version$]" />
<dependency id="MyPackage.Web" version="[4,5)" />
</group>
<group targetFramework="net40">
<dependency id="MyPackage.MVC4.Core" version="[$version$]" />
<dependency id="MyPackage.Web" version="[4,5)" />
</group>
<group targetFramework="net45">
<dependency id="MyPackage.MVC4.Core" version="[$version$]" />
<dependency id="MyPackage.Web" version="[4,5)" />
</group>
</dependencies>
</metadata>
</package>
This keeps the upgraded version of MyProject.Web at the current version, but when installed in a new project the version of MyPackage.Web never exceeds 4.0.x even when the latest version is higher.
If I try the other end of the spectrum and use $version$, which gets replaced with the current version, then people with older versions of NuGet end up having their configuration files reset when they upgrade because they are forced to update their package.
So I would like to try a different approach. I am thinking that putting the files into a "first" directory and then copying them recursively only if they don't already exist is the target project. However, I ran into another snag - there doesn't appear to be any documentation for the $package object that is passed into the install.ps1 script.
Are there any other options of how to meet this requirement that I am unaware of?