.NET Error: “The current NET SDK does not support targeting NET 7.0.”

The current NET SDK does not support targeting NET 7.0. Either target . NET 6.0 or lower, or use a version of the NET SDK that supports .NET 7.0.

This error message is indicating that the version of the .NET SDK that you are currently using does not support targeting .NET 7.0. In order to resolve this error, you have three options:

  • Update your Visual Studio instance to the latest available.
  • Target .NET 6.0 or lower in your application by modifying the target framework in your project file (e.g. .csproj) to a version lower than 7.0, and then rebuild your application.
  • Use a version of the .NET SDK that supports .NET 7.0. You can check the version of the SDK you are currently using by running dotnet --version in a command prompt or terminal, and then update it to the latest version that supports .NET 7.0.
    • You can check the SDK version by running dotnet –list-sdks and you can update your SDK version by running dotnet update sdk
    • Once you have updated your SDK version, you should be able to build your application targeting .NET 7.0 without encountering this error.
This content has 1 year. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

dotnet tool/workload installation fails, because of custom NuGet sources

If you are facing this issue when using dotnet’s workload install, or tool install:

Workload installation failed: Unable to load the service index for source https://pkgs.dev.azure.com/SourceNAME/_packaging/ProjectName/nuget/v3/index.json.

Then you probably should invoke the command with the following parameter:

--ignore-failed-sources

Hope this helps 😉

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Code by rules: Make editorconfig to enforce code conventions and consistency

You can add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase. EditorConfig settings take precedence over global Visual Studio text editor settings. This means that you can tailor each codebase to use text editor settings that are specific to that project. You can still set your own personal editor preferences in the Visual Studio Options dialog box. Those settings apply whenever you’re working in a codebase without an .editorconfig file, or when the .editorconfig file doesn’t override a particular setting. An example of such a preference is indent style—tabs or spaces.

EditorConfig settings are supported by numerous code editors and IDEs, including Visual Studio. It’s a portable component that travels with your code, and can enforce coding styles even outside of Visual Studio.

When you add an EditorConfig file to your project in Visual Studio, new lines of code are formatted according to the EditorConfig settings.

EditorConfig visual editor in Visual Studio for Windows

More detailed information, and syntax can be found here:

https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Azure DevOps: Setup private NuGet feed with CI

In case you need a private NuGet feed, you can do it in Azure DevOps. This can be handy for businesses reusing their code between several codebases.

What will contain the example

In this tutorial, I will show you how to share code through NuGet packages so that it can be used in multiple projects. The Example will walk you through the game engine of an IDLE game. IDLE games are games that do not require much user interaction. The point of games is that they run or produce even when the user is not playing them. The goods produced offline can eventually be used by the player, to upgrade producers or to buy more producers.

The game engine is developed on the IDLEGAMEENGINE branch. Different games, such as a restaurant game or a programming game, can use this game engine. The games have a common logic of operation, only the story of the games differs. This design helps in development to fix bugs by only having to fix the bug in one place and it will be fixed in all games.

Step 0: Create your shared code

I will not go into details about the implementation of the game engine in this tutorial. The point is to create source code that you want to share with other source code.

Step 1: Create the NuGet feed

Go to your projects Azure DevOps site, and select Artifacts from the list on the left. Push the Create feed button. You can select from several visibility options for the new feed.

Step 2. Automate NuGet package publish to the feed

You probably have a repository with the code, what you want to share. Go To Pipelines on the left, then create a pipeline to get NuGet packages published automatically. (If you are experienced, you can make Release pipelines) In the following sections, i will guide you through how to make a CI pipeline, to pack and publish the NuGet packages automatically every time the main branch gets updated.

Navigate to Pipelines section

Go to pipelines and Select create pipeline button.

Select where do you store the code what you want to publish to your private NuGet feed. In my case, I store the GameEngine code in Azure DevOps, so I will continue with this.

Select the Repository which contains the code to be shared.

Select the desired build template for the project. I’ve implemented the core code in .NET Core, so i will continue with ASP.NET Core.

By default this template creates you a NuGetToolInstaller task, a Nugetcommand Task, and a VS Build task.

We will add a 4th task which can be added by searching for NuGet task.

Set up the tasks parameters as the following: Command should be push. The path to the NuGet packages to publish should be the path where the VSBuild builds the application.

Select the target feed location properly. My target feed is at the same organization, so it will appear in the dropdown list. For External NuGet server, you will need to specify a connector to that resource.

Ensure that, the NuGet package will only build, when the csproj is configured to build as a NuGet package. You will need the following settings for your project in order to make a NuGet from it.

Save the pipeline and run it. If you have configured everything correctly, you will see a lot of green ticks in the progress window

This seems to be well configured

When you navigate to the Artifacts/Packages section, you will see that the NuGet package has been pushed successfully to the private feed.

The recently pushed NuGet will appear here

Step 3.: Use your private repository on your projects

In order to use the recently updated package, you will need to set up your local Visual Studio instance to be able to use your private feed.

Adding a new package source

Go to your VS settings, select the NuGet section, and click on the Sources subsection. Click On add and define the connection details presented by clicking the “Connect to feed” button in the Azure DevOps / artifacts section.

Once you have configured the Visual Studio well, you will see the NuGet Package available when you are trying to add a new package to your proejct.

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Visual Studio for Mac : Delete all ‘bin’ and ‘obj’ with script

Open a terminal where your source codes are stored, and give out the following command:

sudo find . -iname "bin" -o -iname "obj" | xargs rm -rf

Type your superuser password when the terminal prompts it. This will clean up some hard disk space for you.

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.