How to include the multiple .NET Standard versions in the NuGet package - .net-core

I have created the two projects with respect to support .NET Standard version 1.2 & 1.4 and refer the project.json as per target version. Then create the NuGet package with nuspec below.
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>package id</id>
<version>15.1120.0.1</version>
<authors></authors>
<owners></owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl> </licenseUrl>
<projectUrl></projectUrl>
<iconUrl> </iconUrl>
<description> </description>
<copyright></copyright>
<tags> </tags>
<dependencies>
<group targetFramework=".NETStandard1.2">
<dependency id="Microsoft.NETCore.Portable.Compatibility"
version="1.0.1" />
<dependency id="NETStandard.Library" version="1.6.0" />
</group>
<group targetFramework=".NETStandard1.4">
<dependency id="Microsoft.NETCore.Portable.Compatibility" version="1.0.1" />
<dependency id="NETStandard.Library" version="1.6.0" />
</group>
</dependencies>
</metadata>
</package>
It creates the package properly. Now I want to refer this package in the .NET core 1.0 version application with .NET framework 4.6.1. As pre-the .NET Standard Support It should refer the .NET Standard 1.4 version. But it refers .NET Standard 1.2 reference. What I was missing in the package creation. Also,can we please let me know whether we can include multiple target in .NET Standard or not?

Related

NuGet: Package was restored using .NET Framework instead of net5.0

I am new to both .NET core and NuGet releasing.
I built a .NET Core 5.0 class library.
I built a .NET Core 5.0 console app to test this class library
If the test console app directly reference the DLL built from this class library, everything works fine.
If I build a NuGet package using the class library and release it, then download that package to the test console app, I get this warning:
"Package SkyBridge.ClientAPI.NetCore 1.0.0.3 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 net5.0.
This package may not be fully compatible with your project."
This is the nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>SkyBridge.ClientAPI.NetCore</id>
<version>1.0.0.3</version>
<title>SkyBridge.ClientAPI (.NET Core)</title>
<authors>Front Edge Software, Frank Lieu</authors>
<owners>Front Edge Software, Frank Lieu</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<license type="file">SkyBridge_Client_API_Software_License_Agreement.txt</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<description>A class library used to act as a SkyBridge client and communicate with another SkyBridge client.</description>
<summary>A class library used to act as a SkyBridge client and communicate with another SkyBridge client.</summary>
<releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright ©2021 Front Edge Software</copyright>
<tags>Front Edge SkyBridge Client API Remoting</tags>
<dependencies>
<dependency id="Crc32.NET" version="1.2.0" />
<dependency id="BouncyCastle.NetCore" version="1.8.10" />
<dependency id="BouncyCastle.NetCoreSdk" version="1.9.3.1" />
<dependency id="System.Configuration.ConfigurationManager" version="6.0.0" />
</dependencies>
</metadata>
<files>
<file src="SkyBridge_Client_API_Software_License_Agreement.txt" target="" />
</files>
</package>
What is the problem?
The following nuspec solved the problem - I specified the .NET dependency:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>SkyBridgeAPI.NetCore</id>
<version>1.0.0.6</version>
<title>SkyBridgeAPI (.NET Core)</title>
<authors>Front Edge Software, Frank Lieu</authors>
<owners>Front Edge Software, Frank Lieu</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<license type="file">SkyBridgeAPI_Software_License_Agreement.txt</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<description>A class library used to act as a SkyBridge client and communicate with another SkyBridge client.</description>
<summary>A class library used to act as a SkyBridge client and communicate with another SkyBridge client.</summary>
<releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright ©2021 Front Edge Software</copyright>
<tags>Front Edge SkyBridge API Remoting</tags>
<dependencies>
<group targetFramework="net5.0">
<dependency id="Crc32.NET" version="1.2.0" />
<dependency id="BouncyCastle.NetCore" version="1.8.10" />
<dependency id="BouncyCastle.NetCoreSdk" version="1.9.3.1" />
<dependency id="System.Configuration.ConfigurationManager" version="6.0.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="SkyBridgeAPI_Software_License_Agreement.txt" target="" />
<file src="lib\net5.0\FrontEdge.SkyBridgeAPI.dll" target="lib\net5.0" />
</files>
</package>

How can I make an assembly for .net core 3.1 and .netstandard2.0?

Can anyone please tell me what's the correct approach? This is my project file
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
and this is parts of the nuspec file
<dependencies>
<group targetFramework=".NETStandard2.1">
<dependency id="Microsoft.CSharp" version="4.7.0" />
</group>
<group targetFramework=".NetCore,Version=3.1">
<dependency id="Microsoft.CSharp" version="4.7.0" />
</group>
</dependencies>
<packageTypes>
<packageType name="Dependency" />
</packageTypes>
</metadata>
<files>
<file src="bin\$configuration$\**\*.*" exclude="**\*.pdb" target=".\lib"/>
</files>
When building the assembly using Cake we specify Win-x64 as the runtime. Is this correct?
The file/folder structure in the generated nupkg is
\lib
\netcoreapp3.1
\any
\win
\win-x64
\netstandard2.0
\win10-x64
Tools: VS2019, NuGet v5.4.0
Then when I try to install it in a .net core 3.1 project I get the dreaded:
Error NU1202 Package JDM.Common.Json 0.2.2 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package JDM.Common.Json 0.2.2 does not support any target frameworks. ...
I must admit that not being able to get this working is driving me crazy.
TIA
There is no need to create a nuspec file for this. You can use the plural TargetFrameworks and specify multiple target frameworks:
<PropertyGroup>
<TargetFramework>netstandard2.1;netcoreapp3.1</TargetFramework>
</PropertyGroup>
Then you can create the .nupk file using dotnet pack

netstandard 2.0 package is not compatible with netcoreapp2.2 project

I created a nuget package which one of my "netcoreapp2.2" projects references.
The nuspec for the package supports multiple frameworks:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyPackage</id>
<version>1.0.0.0</version>
<description>Description</description>
<authors>Me</authors>
<dependencies>
<group targetFramework=".NETFramework4.0">
<dependency id="Dapper.StrongName" version="1.50.5" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Dapper.StrongName" version="1.50.5" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\Release\net452\MyPackage.dll" target="lib\net40\" />
<file src="bin\Release\net452\MyPackage.pdb" target="lib\net40\" />
<file src="bin\Release\netstandard2.0\MyPackage.dll" target="lib\netstandard2.0\" />
<file src="bin\Release\netstandard2.0\MyPackage.pdb" target="lib\netstandard2.0\" />
</files>
</package>
As my app is a "netcoreapp2.2" app, I would expect it to be happy referencing a "netstandard2.0" package, but I get this error:
Package MyPackage 1.0.20191009.9 is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Package MyPackage 1.0.20191009.9 supports:
[15:37:55][restore] - net40 (.NETFramework,Version=v4.0)
[15:37:55][restore] - netstandard2.0 (.NETStandard,Version=v2.0)
Am I missing something in my nuspec to tell it that this netstandard2.0 package is compatible with netcoreapp2.2?

Strange error while trying to use desktop bridge for wpf

I am trying to use Visual studio project template for desktop bridge to add to wpf app and it will not build successfully and shows this strange warning that i have attached.
warning when building desktop bridge project template
i had followed this post on official documentation :
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net
and before that i had used this blog post to add winmd and runtime to my project:
https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/
and here is the code form Package.appxmanifest file:
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp rescap iot">
<Identity Name="09b95fbd-84cc-426f-9fd2-2c1d3d304fab" Publisher="CN=SO-PC-005" Version="1.0.0.0" />
<Properties>
<DisplayName>WapProjTemplate</DisplayName>
<PublisherDisplayName>SO-PC-005</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements DisplayName="WapProjTemplate" Description="WapProjTemplate" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<iot:Capability Name="systemManagement" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
I also would like to mention that i am trying to use windows.graphics.display for brightness override in a wpf app and it requires systemManagement capapbility. And also that my project builds successfully without packaging project but when I add packaging project to my wpf solution it will not build.

Xamarin Forms PCL to .NET Standard Upgrade - Seeing All NuGet Packages?

I have a Xamarin Forms app which was built with PCL.
When installing NuGet packages I would see all packages installed in NuGet Explorer.
Example Android Project:
Xam.Plugin.Geolocator **5.0.0.187-beta**
It might rely on the following NuGets:
However, when I install Xam.Plugin.Geolocator in the .NET Standard 2.0 solution I don't see the other plugins in the Nuget Package Explorer like I did in PCL project.
Regardless, the Forms App works just fine. Why don't the dependency package show up anymore? How can I know what version of the dependency packages I have installed?
I've gone ahead and manually installed them to the .NET Standard project, but that doesn't feel correct...
Additionally, I've noticed there is no longer a Packages folder in any of my Projects.
In my PCL Solution, I could see the dependencies. See Below:
There should be a Dependencies - NuGet folder for a .NET Standard SDK style project. There is no Packages folder for an SDK style project.
You can expand the Dependencies - NuGet folder items to see the dependencies. If there are no child nodes then there are no dependencies.
You can also see more detailed information in the project.assets.json file which is created in the obj directory after restoring the NuGet packages.
Xam.Plugin.Geolocator has just the .NET Standard.Library NuGet package as a dependency if you are installing it into a .NET Standard project. This NuGet package would be referenced by default in a .NET Standard project. When I install that into a .NET Standard 2.0 project in Visual Studio 2017 it shows no dependencies.
The full set of dependencies taken from the .nuspec file is:
<dependencies>
<group targetFramework=".NETFramework0.0" />
<group targetFramework="Windows0.0" />
<group targetFramework="WindowsPhone0.0" />
<group targetFramework="WindowsPhoneApp0.0" />
<group targetFramework=".NETStandard1.0">
<dependency id="NETStandard.Library" version="1.6.1" />
</group>
<group targetFramework="MonoAndroid1.0">
<dependency id="Xamarin.GooglePlayServices.Location" version="60.1142.0" />
<dependency id="Plugin.Permissions" version="2.2.1" />
</group>
<group targetFramework="Xamarin.iOS1.0">
<dependency id="Plugin.Permissions" version="2.2.1" />
</group>
<group targetFramework="Xamarin.Mac2.0" />
<group targetFramework=".NETPortable0.0-Profile259" />
<group targetFramework="UAP0.0" />
<group targetFramework=".NETPlatform5.0" />
<group targetFramework="Xamarin.TVOS0.0" />
<group targetFramework="Xamarin.WatchOS0.0" />
</dependencies>
If you try other NuGet packages, such as say AutoMapper, then you will dependencies when you expand the Dependencies - NuGet - AutoMapper item in the Solution Explorer.

Resources