Home > front end >  Visual Studio 2022. Can I build project with `dotnet build` by default instead of MSBuild?
Visual Studio 2022. Can I build project with `dotnet build` by default instead of MSBuild?

Time:12-05

I want to develop, build and deploy app to my Raspberry Pi 3 from Visual Studio 2022 on my working PC with Windows 10.

Found, that I can build native Linux app with dotnet.exe build -r linux-arm64 .\TestLinuxDeploy\TestLinuxDeploy.csproj --self-contained

So, can I somehow modify single project behavior, to make default build (Ctrl Shift B) to run above command instead of building with MSBuild? Or redefine default MSBuild Build target, or something else...

My stack of googled info literally overflowed with tons of information about VS build process, but no clear one.

I expect, that I can define some properties in .csproj file, like runtime, self-contained, single-package, then hit big red "BUILD" button, and project will be built with dotnet build <my parameters>

CodePudding user response:

Yes, you can modify the default build behavior in Visual Studio to use the dotnet build command you mentioned. To do this, you will need to edit the project file for your .NET Core app (the .csproj file).

To specify the runtime, self-contained, and single-package options for the dotnet build command, you can add the following elements to your project file:

<PropertyGroup>
  <RuntimeIdentifier>linux-arm64</RuntimeIdentifier>
  <PublishSingleFile>true</PublishSingleFile>
  <PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

These elements will tell the dotnet build command to build your app for the Linux ARM64 platform, and to create a single, self-contained package for deployment.

Once you have added these elements to your project file, you can use the Visual Studio "Build" button to build your app using the dotnet build command with these options.

Alternatively, you can also specify these options on the command line when running the dotnet build command. For example:

dotnet build -r linux-arm64 .\TestLinuxDeploy\TestLinuxDeploy.csproj --self-contained --single-file

This will build your app using the specified runtime and options, without modifying the project file.

I hope this helps!

  • Related