2

We have a legacy VB.NET application. The frontend is being redesigned in MVC 5, and I was assigned to abstract the business logic to an API.

I created a library with some code to make calls to the API (so the developer building the MVC 5 app can easily install/update the package and use it).

But I would like to help the developer responsible to redesign the VB.NET project to consume the API with the same NuGet package.

Is it possible to create one NuGet package compatible with both, or do I really need to make two packages?

I read something about .NET Standard, but I couldn't find anything about VB.NET, it looks they work for C# only (I'm not sure).


If it's possible, should the VB.NET project use the same .net framework version as the package in order to work?

Alisson Reinaldo Silva
  • 10,009
  • 5
  • 65
  • 83

2 Answers2

12

A compiled .Net DLL is language agnostic: you can use a DLL written in any .Net language from any .Net language.

Note that in general you can only reference .Net DLL (.Net assembly) that is compiled for that or lower version of .Net compared to one you set target .Net version of code you compile. Ideally both DLL (on in NuGet and VB.Net) target the same .Net version, otherwise read MSDN: Version Compatibility in the .NET Framework.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
4

The language does not matter for .Net Nuget packages because they all compile to the framework(s) they target. This means C# assemblies compiled from C# code can be decompiled into C# or VB .Net regardless of the original language they were created in.

A little more detail:

Nuget packages are limited by the framework version they target, so your legacy app should preferably target the latest version of the .Net framework (4.7.1 as of this post) if you want to maximally utilise third party libraries and target the latest .net standard (2.0 as of writing).

.Net Standard is a compatibility standard, which means that if a language runtime version supports that version of the standard, it is guaranteed to have certain APIs available.

https://learn.microsoft.com/en-us/dotnet/standard/net-standard

Based on the table in that documentation, if your legacy application is targeting .net framework 4.5, you can only build libraries that target .net standard 1.1. Any higher version for your nuget package will prevent you from using it in your legacy app.

Tjaart
  • 3,912
  • 2
  • 37
  • 61
  • Is that statement true? `C# assemblies can be decompiled into C# or VB .Net` - if I didnt understand you wrongly you are implying that if I use a "C# assembly" (does such thing even exist) - a VB.Net assembly will decompile the dll on runtime to make it work - sorry but I strongly believe thats just wrong - if I understood your correctly – Rand Random Feb 19 '18 at 18:57
  • @RandRandom what I mean is that an assembly that was compiled from c# code can be decompiled into vb .net. I'll fix the sentence. – Tjaart Feb 19 '18 at 18:58
  • 1
    You probably should add that [.NET Standard is the replacement for Portable Class Libraries (PCL)](https://learn.microsoft.com/en-us/dotnet/standard/net-standard#comparison-to-portable-class-libraries) and that it doesn't have a runtime. It is just a type forwarding mechanism for multiple runtimes. Many people seem to be confused about the fact that [class libraries targeting .NET Standard are not executable](https://stackoverflow.com/a/48831013/), but they can be referenced by executable assemblies. – NightOwl888 Feb 19 '18 at 19:10
  • @RandRandom there is assembly (like ".Net Assembly", also known as ".Net DLL", "managed DLL",...) and assembly (like "readable textual representation of machine code"). I strongly suspect you use that word in both meanings at the same time thus confusing yourself... I'd recommend reading some basic information about .Net (or if you have not time just https://en.wikipedia.org/wiki/Common_Intermediate_Language could be a good start). – Alexei Levenkov Feb 19 '18 at 19:50
  • @AlexeiLevenkov - only know the term "managed DLL" and consider ".Net Assembly/.Net DLL/C# Assembly/F# Assembly/VB Net Assembly" and what not just wrong – Rand Random Feb 19 '18 at 19:58
  • 1
    @RandRandom https://msdn.microsoft.com/en-us/library/ms973231.aspx... It is somewhat an old article (2002), but it may convince you to at least reconsider your "'.Net assembly' is just wrong" position. – Alexei Levenkov Feb 19 '18 at 20:03