hi i want create multi target nuget package. Everything seems to work well Except that whene i create wpf NetCore3 app and install my package The .NET Framework dll is used and The NetCore3 library is not used
<files>
<file src="lib\netcore\Control.dll" target="lib\netcore" />
<file src="lib\net48\Control.dll" target="lib\net48" />
<file src="lib\net40\Control.dll" target="lib\net40" />
<file src="lib\net40\Microsoft.Windows.Shell.dll" target="lib\net40" />
</files>
Is this lib\netcore correct?
You should use the same TFM in the package as your csproj has in the <TargetFramework> element. If your csproj has <TargetFramework>netcore</TargetFramework>, then sure, use lib/netcore/whatever.dll. But if your csproj has <TargetFramework>netcoreapp3.0</TargetFramework>, then you should use lib/netcoreapp3.0/whatever.dll.
However, SDK style projects, the only type that work with .NET Core 3.0, support multi-targeting (change <TargetFramework> to <TargetFrameworks>, then use a semicolon delimited list netcoreapp3.0;net48;net40), and NuGet's pack targets know how to pack these projects automatically. So there is no need to create a nuspec yourself, which minimises the risk of making these types of mistakes.
So, just as NuGet's docs on creating multi-targeting packages says, just use dotnet pack to create your package, and let NuGet figure out what lib/* folders to use. Avoid using nuspec files. Any other metadata you specify in the nuspec can specified via MSBuild properties in your csproj.
netcore is a Microsoft Store TFM.
For your .NET Core 3 (netcoreapp3.0) WPF app, you'd need to multi-target with netstandard or netcoreapp in your NuGet package.
For example:
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
Related
I'm interested in using the Stylecop.Analyzers nuget package, because it integrates Stylecop with Roslyn and because of that builds will fail if they do not meet the defined requirements. The idea that I have is as follows:
I create a custom nuget package containing a stylecop.json file and a Stylecop.Analyzers.ruleset file, with the package having a dependency on Stylecop.Analyzers.
I am able to get this to work in a .Net Core 2 project if I add the mentioned files manually and make the following changes to the .csproj:
<PropertyGroup>
<CodeAnalysisRuleSet>Stylecop.Analyzers.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
and the following for the stylecop.json file:
<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
Now I would like to automate this with the Nuget package, so I can easily install and use this in a variety of solutions/projects. Unfortunately I am not able to do this.
The first problem I run into is that I'm unable to update the .csproj from a nuget package. I tried to do so by creating the folder structure mentioned in the following thread: Providing a code analysis ruleset to a .net core project through NuGet
This did not seem to do anything...
Next I tried to solve this by using a Powershell install script that transforms the .csproj. I cloned the following project on Github: https://github.com/FantasticFiasco/csproj-ignition that uses Powershell to update the csproj. I tested this and I did get it to work for .Net Framework projects, but unfortunately not for my .Net Core 2 project.
So in short: does anyone know how to transform the .csproj of a .Net Core 2 project through the installation of a nuget package or is this mission impossible?
How do I package a Universal Windows Platform library that depends on Visual Studio extension SDKs such as the Microsoft Player Framework?
Specifically, I want users of my library to be able to use it immediately after pressing the Install button in NuGet, without having to manually add the extension SDKs to their projects. Assuming, of course, that the appropriate extension SDKs are actually installed.
This is a series of questions and answers that document my findings on the topic of modern NuGet package authoring, focusing especially on the changes introduced with NuGet 3. You may also be interested in some related questions:
How to package a .NET Framework library?
How to package a .NET library targeting the Universal Windows Platform?
How to package a portable .NET library targeting .NET Core?
How to package a .NET library targeting .NET Framework and Universal Windows Platform and include platform-specific functionality?
How to package a multi-architecture .NET library that targets the Universal Windows Platform?
This answer builds upon the principles of .NET Framework library packaging and the principles of Universal Windows Platform library packaging. Read the linked answers first to better understand the following.
When you directly reference a Visual Studio extension SDK in a project, the following snippet is included in the .csproj file:
<SDKReference Include="Microsoft.PlayerFramework.Xaml.UWP, Version=3.0.0.2">
<Name>Microsoft Player Framework</Name>
</SDKReference>
NuGet offers functionality that enables an equivalent action to be performed when installing a NuGet package. The first thing you must do is to create in your project a .targets file (e.g. MyLibraryUsingExtensionSdk.targets) that contains the relevant XML to be added to the project into which your library is installed. You will want to copy the relevant <SDKReference> element from your library's .csproj file and also include any parent elements, creating a full XML document that can be merged.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SDKReference Include="Microsoft.PlayerFramework.Xaml.UWP, Version=3.0.0.2">
<Name>Microsoft Player Framework</Name>
</SDKReference>
</ItemGroup>
</Project>
Set the build action of this file to None, to avoid it being needlessly touched by the build process.
By including this .targets file in the appropriate location in the NuGet package structure, it will be automatically merged at runtime into projects that make use of your library. You want to achieve the following package structure:
+---build
| \---uap10.0
| MyLibraryUsingExtensionSdk.targets
|
\---lib
\---uap10.0
| MyLibraryUsingExtensionSdk.dll
| MyLibraryUsingExtensionSdk.pdb
| MyLibraryUsingExtensionSdk.pri
| MyLibraryUsingExtensionSdk.XML
|
\---MyLibraryUsingExtensionSdk
ExampleControl.xaml
MyLibraryUsingExtensionSdk.xr.xml
You can create such a package using the following .nuspec template:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="3.2">
<id>Example.MyLibraryUsingExtensionSdk</id>
<version>1.0.0</version>
<authors>Firstname Lastname</authors>
<description>Example of a simple UWP library that depends on an extension SDK.</description>
</metadata>
<files>
<!-- Causes referencing this NuGet package to also automatically reference the relevant extension SDKs. -->
<file src="MyLibraryUsingExtensionSdk.targets" target="build\uap10.0\MyLibraryUsingExtensionSdk.targets" />
<file src="..\bin\Release\MyLibraryUsingExtensionSdk**" target="lib\uap10.0" />
</files>
</package>
Note that Visual Studio will require a solution reload to fully recognize the extension SDK after installing such a NuGet package. Builds will work immediately without problems but IntelliSense will not pick up the new extension SDK until a reload.
Unfortunately, this approach does require you to hardcode the version number of the extension SDK, which can be problematic. At the moment of writing, I know of no way to specify a range of versions or a version-independent reference.
Remember to build your solution using the Release configuration before creating the NuGet package.
A sample library and the relevant packaging files are available on GitHub. The solution corresponding to this answer is UwpLibraryDependingOnExtensionSdks.
As I developer I wonder which is the best approch to create a nuget packages ?
1.NuGet Package Project (link)
2.Use Nuget.exe use .Nuspec (add manually and update manually)
Anyone guide on this.
Currently I'm using nuget.exe and .Nuspec but problem is everytime I have to manually update .nuspec if any new project is added.
Is there any other good options to do so ?
You can also build a NuGet package by running the nuget pack command against the csproj file. More information can be found here: Creating And Publishing A Package
Create nuget package in the following manner
Download nuget.exe from here https://www.nuget.org/
Create empty spec file (execute below command under project root folder)
nuget spec
Update nuget spec file SomeLib.nuspec according to your library properties(use any text editor)
Create some folders nugetPack/lib/net46/ and then paste the dll here; which you want to make as nuget package
Create nuget package (execute below command under project root folder)
nuget pack -basepath nugetPack SomeLib.nuspec
Now use this nuget package in your project
Set the nuget package source which you have created
Goto Visual Studio > Tool > NuGet Package Manager > Package Sources > here add your nuget package source folder path
Right click and select managae nuget packages on the project where you want to consume nuget package.
Select the right package source from the top right drop down box.
search your nuget package and install.
Another cool way to create nuget package via NuGet Package Explorer
which you can download it from here https://npe.codeplex.com/ then just simply fill the form and save the nuspec file to your local nuget package source folder.
Sample nuspec file whihc has some dependencies
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>your.package.name</id>
<version>1.0.0</version>
<title>package title</title>
<authors>NG</authors>
<owners>NG</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>some description</description>
<summary>some summary</summary>
<copyright>open</copyright>
<language>en-US</language>
<tags>your package keyboards</tags>
<dependencies>
<dependency id="Microsoft.AspNet.WebApi.Core" version="5.2.3" />
<dependency id="Microsoft.AspNet.WebApi.Client" version="5.2.3" />
<dependency id="Newtonsoft.Json" version="9.0.1" />
</dependencies>
</metadata>
</package>
Github README
I'm new to developing nuget packages, (and posting on Stack Overflow). I started using the nuget.exe command-line approach, which I learned about: here. But from what I've gathered so far, there is a convention of using .NET Standard, instead of .NET Framework when developing nuget packages. Especially on nuget.org. So, when developing a .NET Standard class library, check out the project properties under the project tab in Visual Studio. There you will see multiple tabs on the left, starting with build. Click on the Package tab. Now you'll see a great way to enter all properties that you would normally have to do manually when trying to create the .nuspec file. You'll want to be sure to fill it out completely to avoid flags when uploading to nuget or wherever. Create your repository and file in github, and enter their URLs. Also, imgur.com is a great place to host your icon image. Be sure to click the Generate Nuget Package checkbox. Voila! Now build your library and you'll notice a .nupkg file. This is the best resource.
I want to create a nuget package that contains besides .NET assemblies "legacy" DLLs (non .NET DLLs), which are referenced or accessed by the assembly DLLs.
Where do I put these DLLs? How does the users program (exe), which uses my package, get access to these DLLs?
I can only think of two ways the users program can access these DLLs: either there is a PATH environment variable set to the appropriate directory or these DLLs are copied into the bin/Release and bin/Debug directories of the users project.
How would I deal with x86 and x64 versions of the legacy DLLs?
I would look at adding a custom MSBuild .targets to your NuGet package. Inside this .targets file you can define any MSBuild tasks you need which will allow you to hook into the build of the project. So you could have the non-.NET dlls copied into the output directory using MSBuild.
The PostSharp NuGet package is one example that copies extra files around during the build. However its MSBuild .targets file is fairly complex. You would not need to do anything as complicated as that. Probably something simple similar to:
<PropertyGroup>
<PrepareForRunDependsOn>$(PrepareForRunDependsOn);MyPostBuildTarget</PrepareForRunDependsOn>
</PropertyGroup>
<ItemGroup>
<ExtraFile Include="dlls\*.dll" />
</ItemGroup>
<Target Name="MyPostBuildTarget">
<Copy SourceFiles="#(ExtraFile)" DestinationFolder="$(OutputPath)" />
</Target>
The above is only an idea of what you could do.
I'm trying to automate creating a NuGet package to include .js files within my web project via Visual Studio 2013 when builds are run. I have done this using the NuGet Package Explorer but this needs to be automated.
I have used the Nuget package "CreateNewNuGetPackageFromProjectAfterEachBuild" and this seems close but the CreateNuGetPackage.ps1 script restricts to csproj files. Has anyone done this? I have searched and read that a powershell solution may be needed.
Does anyone know if this has been solved yet? At this point I'm ready to learn how to write a powershell script.
I suggest you to create proper nuspec file with wildchars like below:
<files>
<file src="bin\Debug\*.dll" target="lib" />
<file src="bin\Debug\*.pdb" target="lib" />
<file src="tools\**\*.*" exclude="**\*.log" />
</files>
and run just: nuget.exe pack yournuspec.nuspec