Error when adding new Nuget to a .Net Standard Project - nuget-package-restore

I am working on referencing another set of .dlls in another project and have bundled it up via Nuget:
I get this error:
Severity Code Description Project File Line Suppression State
Error NU1701 Package 'MyPackageImTryingToInstall' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project. 1
I understand the error, but how do I make .Nuget restore with .Net standard?
Just found that if I reference the Nuget in a .Net Framework 4.6.1 project - it works fine.
It has something to do with making a nuget from .net standard to .net standard.

I had to add lib folders for the target frameworks I wanted to add the nuget package to:
For the files section in the nuspec I needed to make a \netstandard2.0 folder and \461 folder

Related

How can i make archive iPA in Visual studio MAC. error occur in latest version

Package 'Microsoft.Bcl 1.1.6' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
According to the error message you provided, it lists some supported versions of NETFramework and you are using NETStandard.
So You should change your projecr target framework from .NETStandard to .NETFramework.

How to keep same version for all the projects while generating NuGet package using pack command

I've following structure for a .NET Framework project:
-->ProjectSoln -------->ClassLibProj1 -------->ClassLibProj2 -------->ConsumerLibProj3
I've defined GlobalAssemblyInfo.cs file at solution level and added the reference to this file in all
the 3 projects. ConsumerLibraryProj3 has project reference to ClassLibraryProj1 and ClassLibraryProj2.
I've added nuspec file in the ConsumerLibProj3 that contains $version$.
I'm generating Nuget Package for the ConsumerLibraryProj3 using following command
nuget pack ConsumerLibProj3.csproj -includereferencedprojects -verbosity detailed
The package gets generated successfully, but the version of the ClassLibProj1 and ClassLibProj2 dlls
in the package is not the latest. e.g. in the package ConsumerLibProj3.dll has version 1.0.0.2
whereas the ClassLibProj1.dll and ClassLibProj2.dll has version 1.0.0.1. The expectation is that all
the three dll's should have same version because the the version is coming from the
GlobalAssemblyInfo.cs file. The solution is using .NET Framework type project. Any help will be appreciated.
At last I was able to resolve this issue by forcing the nuget to use release configuration while packing. Surprisingly, I was building the solution with Release profile but still nuget was getting confused somehow. I used following command
nuget pack ConsumerLibProj3.csproj -includereferencedprojects -build -properties configuration=release -verbosity detailed
Thanks for the help.

How to push an update to a NuGet feed for .NET Framework and .NET Core libraries

I have my own NuGet feed in Azure Artefacts. Currently, there are two packages in the feed:
INTLConfiguration.Client [Version 1.0.0]
INTLConfiguration.NetFramework.Client [Version 1.0.0]
The top one is a .NET Core library and the bottom one is a .NET Framework library.
I need to push an update to the NuGet feed for both versions to be 1.0.1 - but I'm having some trouble doing this. I packed 'INTLConfiguration.Client' and renamed the .nukpg from INTLConfiguration.Client.1.0.0.nupkg to INTLConfiguration.Client.1.0.1.nupkg and tried to push the nuget to my source feed but it errored with a conflict message saying v1.0.0 already exists.
How do I go about updating both of these nuget packages into my source feed?
Thank you.
I packed 'INTLConfiguration.Client' and renamed the .nukpg from
INTLConfiguration.Client.1.0.0.nupkg to
INTLConfiguration.Client.1.0.1.nupkg
It seems that your update is just to rename the output xxx.nupkg. It's not the valid way to create updated .nupkg. A xx.nupkg is something like a .zip. Renaming it from Name.nupkg to Name.zip and then you can unzip it and see its content. Open the ProjectName.nuspec and you can find the version defined in it is still 1.0.0.
My guess:
Maybe the way you use to pack is something like creating a .net core project and right-click the pack button which outputs a ProjectName.1.0.0.nupkg.
1# If so, the easiest way to resolve it is right-click Project name in Solution Explorer=>Properties and change the Package version there:
Change the version to 1.0.1 and pack it again.
2# Also we can use .nuspec file defined by us for this option.
Add a text file to the project and rename it to xxx.nuspec. Change its build action in property window to content.
Right-click the project=>unload the project=>edit the xxx.csproj file.
Add a script like below into it:
<PropertyGroup>
<NuspecFile>NuspecName.nuspec</NuspecFile>
</PropertyGroup>
Then reload the project, every time when we use Pack option it will call NuspecName.nuspec file.
To create a nuget package by command-line, I suggest you use dotnet.exe or nuget.exe.
For your .net core project, you can use dotnet pack command.Some details about it see here.
3# To create a .net core package with version 1.0.2 without using a .nuspec file:
Open cmd.exe, and type command: cd C:\PathToProjectFolder to navigate to ProjectDir(where exists xx.csproj)
Then type command like dotnet pack -p:PackageVersion=1.0.1 to create a really version-1.0.1 nuget package. (If you only have one .csproj in the dir)
Or you need to specify the .csproj like: dotnet pack ~/projects/app1/project.csproj -p:PackageVersion=1.0.1
4# To create a .net core package with version 1.0.2 using a .nuspec file:
Create a .nuspec file and modify its content to meet your needs(Version, AuthorName...).
Open cmd.exe and use a command like:dotnet pack ~/projects/app1/project.csproj /p:NuspecFile=~/projects/app1/project.nuspec /p:NuspecBasePath=~/projects/app1/nuget
If you use the Pack option(Right-click project=>Pack button) in VS, check 1# or 2#.
If you use command-line, you can check 3# or 4#. Hope it helps:)
Update:
How do I go about updating both of these nuget packages into my source
feed?
You can check this tutorial to create a package which targets .net framework.And update the version in .nuspec before you pack it. Also, if you want to get an updated nuget package, I suggest you update the assembly version and file version for the dll itself also.

Xamarin.Android: Package XX is not compatible with monoandroid81 (MonoAndroid,Version=v8.1)

I encounter a stranger behavior with a Xamarin.Android project in Visual Studio on Windows.
I've created a new Android blank project, and I try ton install the NuGet package "AForge" (a mathematics library), but I get the following error message:
Package AForge 2.2.5 is not compatible with monoandroid81
(MonoAndroid,Version=v8.1).
I've already tried to re create several projects, after having relaunched Visual Studio and the computer, but the problem is still the same.
However, if I do the same thing on Mac, through Visual Studio for Mac, I don't encounter the same problem: the package is well installed.
In add, I can see in the package.config file, that the package il well related to monodroid81:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AForge" version="2.2.5" targetFramework="monoandroid81" />
</packages>
Would you have any explanation about this issue?
Update: new issue
Hi #Leo Liu-MSFT, I come back to you as I encounter an new issue. The dll copy works fine locally, but I get an error on AppCenter:
CoreCompile:
/Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/4.5/csc.exe
/noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4
/define:DEBUG;TRACE;XAMARIN_ANDROID_v1_0;MOBILE;ANDROID;ANDROID_1;ANDROID_2;ANDROID_3;ANDROID_4;ANDROID_5;ANDROID_6;ANDROID_7;ANDROID_8;ANDROID_9;ANDROID_10;ANDROID_11;ANDROID_12;ANDROID_13;ANDROID_14;ANDROID_15;ANDROID_16;ANDROID_17;ANDROID_18;ANDROID_19;ANDROID_20;ANDROID_21;ANDROID_22;ANDROID_23;ANDROID_24;ANDROID_25;ANDROID_26;ANDROID_27
/reference:/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll
/reference:/Users/vsts/.nuget/packages/microsoft.appcenter.analytics/1.7.0/lib/MonoAndroid403/Microsoft.AppCenter.Analytics.Android.Bindings.dll
/reference:/Users/vsts/.nuget/packages/microsoft.appcenter.analytics/1.7.0/lib/MonoAndroid403/Microsoft.AppCenter.Analytics.dll
/reference:/Users/vsts/.nuget/packages/...
Services/AudioService.cs(8,7): error CS0246: The type or namespace
name 'AForge' could not be found (are you missing a using directive or
an assembly reference?)
[/Users/vsts/agent/2.136.1/work/1/s/XxxApp/XxxApp.csproj] Done
Building Project
"/Users/vsts/agent/2.136.1/work/1/s/XxxApp/XxxApp.csproj"
(PackageForAndroid target(s)) -- FAILED.
So I tried your suggestion, but I get an error when I try to save the package:
a local file header is corrupted'
Would you have another suggestion?
Would you have any explanation about this issue?
You can get the official document here:
Description: With PackageReference, assemblies present at the root of
lib folder without a target framework specific sub-folder are ignored.
NuGet looks for a sub-folder matching the target framework moniker
(TFM) corresponding to the project’s target framework and installs the
matching assemblies into the project.
In this case, NuGet will consider installing this package to the .NET Framework, which is not compatible with monoandroid81. Then you will that error "Package AForge 2.2.5 is not compatible with monoandroid81".
To resolve this issue, the best way is contact the author of the AForge NuGet package to update this package, or you can also add reference dll file directly to your project.
Besides, if you still want to use nuget to manager this package, I would like provide you a workaround to resolve this issue:
Download this nuget package from nuget.org.
Copy the download package, rename it with .zip, like aforge.2.2.5 - Copy.nupkg.zip, then unzip it.
Open the package aforge.2.2.5.nupkg with NuGet Package Explorer(Get it from Microsoft store), add a new folder MonoAndroid81 under the lib node, add exists file AForge.dll and AForge.xml from the copy folder aforge.2.2.5 - Copy.nupkg.zip, save this nuget package.
Add this new create nuget package to the nuget local feed, then add this nuget package to the project. Do not forget delete the nuget package cache in the C:\Users\<UserName>\.nuget\packages\aforge before you add the package.
Hope this helps.

Can't open namespaces in a Nuget package

I did the following:
Create a new F# project in VS2013
In Package Manager Console, execute while targetting the new project:
Install-Package FSharp.Azure.StorageTypeProvider
In the file, type:
open FSharp.Azure.StorageTypeProvider
...as can be seen in the examples included in the Github project.
But I get the error:
"The namespace or module 'FSharp' is not defined"
What am I doing wrong? I am new to Nuget, and this is the first package I've downloaded that hasn't "just work"ed.
My project was targeting .NET framework 4.5 by default. It needed to be targeting 4.5.1.

Resources