nuget package restore

If you are using private feed then make sure you have installed this;

https://github.com/Microsoft/artifacts-credprovider

I ran this command in powershell (admin mode);

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1'))

I have to run this command to restore packages;

dotnet restore –interactive

This command will open up a window and ask you to login to Microsoft website with a code. Login to https://microsoft.com/devicelogin and enter the code. This will do some sort of IDE verification. Close VS and reopen. You should be able to see all of your custom and nuget packages restored.

I found this alternative today;

dotnet restore projectName

This will restore the packages.

From within Visual Studio you can use the Package Manager Console to also update the packages. This has the benefit that any PowerShell scripts will be run as part of the update where as using NuGet.exe will not run them. The following command will update all packages in every project to the latest version available from nuget.org.

Update-Package

You can also restrict this down to one project.

Update-Package -Project YourProjectName

If you want to reinstall the packages to the same versions as were previously installed then you can use the -reinstall argument with Update-Package command.

Update-Package -reinstall

You can also restrict this down to one project.

Update-Package -reinstall -Project YourProjectName

The -reinstall option will first uninstall and then install the package back again into a project.

Close and restart VS. Hopefully this will restore the packages.

Another problem might be yellow triangle icon next to package references. To solve this, make sure you are targeting same framework in multiple projects. Here is a discussion about this;

https://stackoverflow.com/questions/20186216/why-do-i-get-a-warning-icon-when-i-add-a-reference-to-an-mef-plugin-project

Resources

https://github.com/dotnet/sdk/issues/10189

https://stackoverflow.com/questions/6876732/how-do-i-get-nuget-to-install-update-all-the-packages-in-the-packages-config

Project targeting multiple framework in .NET

Edit the .csproj file to support the target frameworks; for example change.

<TargetFramework>netcoreapp2.1</TargetFramework>
to:
<TargetFrameworks>netcoreapp2.1;net45</TargetFrameworks>

Make sure that you change the XML element changed from singular to plural (add the “s” to both the open and close tags).

Resources

https://docs.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file

Multi-Targeting Frameworks

Clarification on development framework in .NET

This always confuses me. Here is the summary;

  • .NET Framework – the original .NET, the one that ships on Windows and only on Windows; the current (and probably final) version of .NET Framework is 4.8
  • .NET Core – the evolution of .NET, that is not tied to the OS as much, with slightly different feature sets, and where most of the Microsoft .NET effort has been for the last few years; .NET Core 3.1 shipped recently
  • .NET Standard – an API definition (not implementation – akin to an interface) that allows a library to target a range of platforms in a single build, i.e. by targeting .NET Standard 2.0 a library can in theory run equivalently on .NET Core 3 and .NET Framework 4.6.2 (ish…) and others (Mono, Unity, etc), without needing to target each individually
  • .NET 5 – the next version of .NET Core; the naming deliberately emphasizes that there isn’t a two-pronged development future consisting of “Framework” and “Core”, but just one – this one – which isn’t “Core” in the “minimal” sense, but is in fact now a very rich and powerful runtime; .NET 4 was avoided to prevent versioning confusion between .NET 4.* and .NET Framework 4.* (and again, to emphasize that this is the future direction of .NET, including if you are currently on .NET Framework)

Best practices for designing REST API

A reference list of best practices;

https://abdulrwahab.medium.com/api-architecture-best-practices-for-designing-rest-apis-bf907025f5f

https://zonito.medium.com/best-practice-and-cheat-sheet-for-rest-api-design-6a6e12dfa89f

https://medium.com/geekculture/minimal-apis-in-net-6-a-complete-guide-beginners-advanced-fd64f4da07f5

https://levelup.gitconnected.com/5-difficult-skills-that-pay-off-exponentially-in-programming-702a599c636e

Sharing libraries between .Net Core and .Net Framework applications

I was trying to reference a DLL targeting FW 4.6 in a host application targeting .NET Core 2.1. I started getting this error;

This is where I started to wonder, What’s the difference? How they can co-exist? How the host application can use them?

Microsoft recommend to target .NET Standard 2.0 when building reusable libraries, unless you need to support an earlier version. Most general-purpose libraries should not need APIs outside of .NET Standard 2.0. .NET Standard 2.0 is supported by all modern platforms and is the recommended way to support multiple platforms with one target.

.NET Core 2.1 and later versions support .NET Standard 2.0 and earlier versions.

There will be no new .NET Standard versions after 2.1. For more information, see .NET 5 and .NET Standard later in this article.

.NET Standard libraries and Visual Studio
In order to build .NET Standard libraries in Visual Studio, make sure you have Visual Studio 2019 or Visual Studio 2017 version 15.3 or later installed on Windows, or Visual Studio for Mac version 7.1 or later installed on macOS.

Start from here

Read about .NET standard here

A good explanation about libraries

Resources