1

I'm new to nuget package publishing.

The project under progress is a dot net core app and it's an open source project.

I undertand the two options content and lib when it comes to specifying target for distribution files.

Because so far I've not been able to connect a dll to a .net core web app on mac and the research indicates that the option is to have source code available for installation/deployment.

Second there could be users on the desktop that can develop their projects using the assembly dll provided.

Question is,

  1. can user select what to get? dll or the source files?

  2. Do I've to create a separate assembly for each, netstandard, netcore, net and uap?

I want to have the assembly (preferable) or source code available for all above mentioned platforms. The binary itself has some functionality that doesn't call any platform specific code, let's assume it's a HelloWorld class embedded inside a DLL.

Images from https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/

enter image description here

enter image description here

user2727195
  • 7,122
  • 17
  • 70
  • 118
  • You've not been able to do what? Describe your problem with every necessary detail please. – Lex Li Mar 05 '17 at 12:18
  • for a .net core app, there's no way that you could link to a dll, so instead I'm copying source code of the assembly for use, however, for programmers on the desktop I'd like to have this distributed as dll, so can you distribute both source code and library to a nugget package and developer can choose what to pick up? – user2727195 Mar 05 '17 at 19:55
  • "All kinds" itself is a crazy idea. Many famous libraries shipped via NuGet targets .NET Standard 1.3. There are some who target 1.0, but really rare. Again, learn from others. What do you mean by "I've not been able to connect a dll to a .NET Core web app on Mac"? If you can link to a NuGet package, then pack up your dll in a NuGet package please. – Lex Li Mar 05 '17 at 20:54
  • Ok, I've edited my question with a screenshot, many platforms there, do I need to create a separate target and provide separate assembly for each? `netstandard`, `netcoreapp`, `net`, `uap`, `win`, `wpa`, `wp`, `mono` etc.? (latest versions only), I'm new to .net and I don't really understand all so if the question doesn't make any sense, please enlighten. – user2727195 Mar 05 '17 at 20:59
  • @LexLi do I've to create a separate assembly for each, netstandard, netcore, net and uap? – user2727195 Mar 05 '17 at 22:35
  • If possible, target your library against .NET Standard 1.0 and it would support all platforms listed in the table. – Lex Li Mar 05 '17 at 23:55
  • ok it's possible since I've simple language constructs (no specific platform based api), second how should I deal with distribution when it comes to having both source code and assemblies. It's an open source so I can distribute both but what's the convention out there? – user2727195 Mar 06 '17 at 00:11
  • Why cannot you publish a NuGet package with only binaries and then a GitHub repo with all source code? Like I commented previously, learn from examples such as JSON.NET and don't waste your time on trying out everything. – Lex Li Mar 06 '17 at 00:19
  • thanks, one last thing, i just learned that `win`, `wpa` and `wp` including `mono` are outdated, so I can use `standard` 1.5 to target `uap`, `net` and `netcoreapp`, correct? – user2727195 Mar 06 '17 at 01:10
  • Read the table (yours above is out of date), and the 1.5 column shows which platforms support it. You would have to use Google again. – Lex Li Mar 06 '17 at 01:28
  • updated charts, it's clear to me now, I'd be using .netstandard 1.6 to target .netframework, .netcore and xamarin. – user2727195 Mar 06 '17 at 01:52

1 Answers1

3

You can make 2 separate NuGet packages:

  1. One that contains the library. Name it "Foo".
  2. One that contains the source code. Name it "Foo.Sources".

Then the user of the package can choose by selecting which package they want.

Another option is to multi-target your NuGet package to both desktop and netstandard/netcoreapp. You would compile your assembly twice, and then contain the separate assemblies in a single NuGet package. There are a few good articles on the web describing this. Here's one: http://blog.csmac.nz/dotnetcore-multi-targeting/. The new .csproj format in VS 2017 allows you to specify <TargetFrameworks>net45;netstandard1.6</TargetFrameworks. You can `dotnet pack Then desktop and .NET Core developers can consume the same package, and they get different assemblies, whichever is built specifically for their framework.

Eric Erhardt
  • 2,286
  • 15
  • 19
  • thanks for also enlightening on multi-targeting, I've another question since I'm relatively new and I'm actually porting a library for .net from another language. so the question is is there another target that I should add and distribute assembly for? for instance this page under the section (NETStandard - an evolution of PCLs) talks about Universal Windows Platform, .NET Platform Standard, windows, windows phone, windows phone silverlight, mono etc. do I've to distribute an assembly for each? https://andrewlock.net/understanding-net-core-netstandard-and-asp-net-core/ – user2727195 Mar 05 '17 at 20:38
  • I've edited and added the screenshot in my question, I'm thrown off by all these multiple platforms, do I've to create an assembly for each? – user2727195 Mar 05 '17 at 20:40
  • 2
    .NET Standard is the framework you should target if you want to run on multiple platforms: .NET Core, UWP, Windows Phone, Mono, etc. If you can target a low enough .NET Standard version, you can run your library almost everywhere. For example, Newtonsoft.Json targets `netstandard1.0`, so it virtually runs on all platforms. However, the lower .NET Standard version you use, the less APIs will be available to you. If you need an API that is only in the .NET desktop Framework, or only on .NET Core, that is when you have to start multi-targeting. – Eric Erhardt Mar 06 '17 at 16:20
  • Thanks for the explanation. – user2727195 Mar 06 '17 at 19:26
  • Can you elaborate on the first approach how to do it? See https://stackoverflow.com/questions/70138346/nuget-package-both-source-and-dlls – Vikash Balasubramanian Nov 28 '21 at 02:07