MSBUILD无法通过task.json运行,但可以通过VS Code终端运行

时间:2019-03-26 12:06:57

标签: visual-studio-code .net-core

我在VS Code 1.32.3下在C#.net-core项目的task.json中有一个构建任务。如果我在task.json中运行任务,它将失败并显示MSBUILD:错误MSB1001:未知开关。 开关:--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

如果我将同一命令复制并粘贴到VS Code终端,它将起作用! --runtime开关中的错误在哪里?

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> 

1 个答案:

答案 0 :(得分:0)

确保在空格处分隔参数。代替:

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

尝试这样的方法:

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

此处的args列表不适用于空格。另外,您也可以利用dotnet CLI也可以使用=来容忍这一事实,因此以下内容也应适用:

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