Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBUILD fails from tasks.json yet works from from VS Code terminal

I have a build task in tasks.json of C# .net-core project under VS Code 1.32.3. If I run the task within tasks.json, it fails with MSBUILD : error MSB1001: Unknown switch. Switch: --run-time linux-arm

Executing task: C:\Program Files\dotnet\dotnet.exe publish --runtime linux-arm --configuration Debug --self-contained false M:\ProjectsGit\HelloWorldVSCode/HelloWorldVSCode.csproj <

Microsoft (R) Build Engine version 16.0.385-preview+g966cdf2ac6 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1001: Unknown switch.
Switch: --runtime linux-arm

If I copy and paste the same command to VS Code terminal it works! Where is the error in the --runtime switch?

PS M:\ProjectsGit\HelloWorldVSCode> dotnet.exe publish --runtime linux-arm --configuration Debug --self-contained false M:\ProjectsGit\HelloWorldVSCode/HelloWorldVSCode.csprojMicrosoft (R) Build Engine version 16.0.385-preview+g966cdf2ac6 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 25.18 ms for M:\ProjectsGit\HelloWorldVSCode\HelloWorldVSCode.csproj.
C:\Program Files\dotnet\sdk\3.0.100-preview-010184\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [M:\ProjectsGit\HelloWorldVSCode\HelloWorldVSCode.csproj]
  HelloWorldVSCode -> M:\ProjectsGit\HelloWorldVSCode\bin\Debug\netcoreapp3.0\linux-arm\HelloWorldVSCode.dll
  HelloWorldVSCode -> M:\ProjectsGit\HelloWorldVSCode\bin\Debug\netcoreapp3.0\linux-arm\publish\
PS M:\ProjectsGit\HelloWorldVSCode> 
like image 701
Gadgetman Avatar asked Mar 26 '19 12:03

Gadgetman


People also ask

Why is my VS Code terminal not working?

Some terminal launch failures may be due to your shell installation and are not specific to VS Code. The exit codes displayed come from the shell and you may be able to diagnose shell issues by searching on the internet for the specific shell and exit code. Use the most recent version of VS Code.

How do I run a JSON file in VS Code?

To create a launch.json file, click the create a launch.json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

What is task json in VS Code?

Tasks in VS Code can be configured to run scripts and start processes so that many of these existing tools can be used from within VS Code without having to enter a command line or write new code. Workspace or folder specific tasks are configured from the tasks. json file in the . vscode folder for a workspace.

Where Is tasks json in VS Code?

You need to configure the tasks in a tasks. json file (located under your workspace . vscode folder) if you want to do more than simply run the task.


Video Answer


1 Answers

Make sure to separate your arguments at spaces. Instead of:

"args": [
   "publish",
   "${workspaceFolder}/HelloWorldVSCode/HelloWorldVSCode.csproj",
   "--runtime linux-arm",
   "--configuration Debug",
   "--self-contained",
],

Try something like this instead:

"args": [
   "publish",
   "${workspaceFolder}/HelloWorldVSCode/HelloWorldVSCode.csproj",
   "--runtime",
   "linux-arm",
   "--configuration",
   "Debug",
   "--self-contained",
   "false",
],

The args list here doesn't take well to spaces. Alternatively, you can make use of the fact that the dotnet CLI tolerates using = as well, so the following should also work:

"args": [
   "publish",
   "${workspaceFolder}/HelloWorldVSCode/HelloWorldVSCode.csproj",
   "--runtime=linux-arm",
   "--configuration=Debug",
   "--self-contained=false",
],
like image 199
Brandon Sharp Avatar answered Oct 19 '22 12:10

Brandon Sharp