如何使msbuild/restore在独立/非SDK项目文件中工作?

如何使msbuild/restore在独立/非SDK项目文件中工作?,msbuild,nuget,packagereference,Msbuild,Nuget,Packagereference,我想对项目文件使用msbuild/restore。但是,我的项目文件更像是一个脚本,它协调构建具有特定属性的多个项目等。因此,设置Sdk=“Microsoft.NET.Sdk”对我来说没有意义,因为这会导致出现奇怪的错误。但是,如果我没有指定Sdk,则会忽略/restore,并且它实际上无法还原任何内容 以下是我的独立项目示例: <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmln

我想对项目文件使用
msbuild/restore
。但是,我的项目文件更像是一个脚本,它协调构建具有特定属性的多个项目等。因此,设置
Sdk=“Microsoft.NET.Sdk”
对我来说没有意义,因为这会导致出现奇怪的错误。但是,如果我没有指定Sdk,则会忽略
/restore
,并且它实际上无法还原任何内容

以下是我的独立项目示例:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <PackageReference Include="RoslynCodeTaskFactory" Version="2.0.7" />
  </ItemGroup>

  <Target Name="Build">
    <HelloWorld/>
  </Target>

  <UsingTask AssemblyFile="$(RoslynCodeTaskFactory)" Condition="'$(RoslynCodeTaskFactory)' != ''" TaskFactory="CodeTaskFactory" TaskName="HelloWorld">
    <Task>
      <Code Type="Fragment" Language="cs">
        <![CDATA[
          Console.WriteLine("Hello, world!");
        ]]>
      </Code>
    </Task>
  </UsingTask>
</Project>



我的调用和输出:

C:\Users\binki\AppData\Local\Temp>"\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /restore helloworld.proj
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2018-05-15 01:23:28.
Project "C:\Users\binki\AppData\Local\Temp\helloworld.proj" on node 1 (default targets).
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5): error MSB4036: The "HelloWorld" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files 9x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64" directory.
Done Building Project "C:\Users\binki\AppData\Local\Temp\helloworld.proj" (default targets) -- FAILED.


Build FAILED.

"C:\Users\binki\AppData\Local\Temp\helloworld.proj" (default target) (1:2) ->
(Build target) ->
  C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5): error MSB4036: The "HelloWorld" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64" directory.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.71
C:\Users\binki\AppData\Local\Temp>“\Program Files(x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe”/restore helloworld.proj
Microsoft(R)针对.NET Framework的生成引擎版本15.7.177.53362
版权所有(C)微软公司。版权所有。
开始建造2018-05-15 01:23:28。
节点1上的项目“C:\Users\binki\AppData\Local\Temp\helloworld.proj”(默认目标)。
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5):错误MSB4036:找不到“helloworld”任务。检查以下内容:1.)项目文件中任务的名称与任务类的名称相同。2.)任务类是“公共”的,并实现Microsoft.Build.Framework.ITask接口。3.)任务在项目文件中或位于“C:\Program files 9x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64”目录中的*.tasks文件中正确声明。
已完成生成项目“C:\Users\binki\AppData\Local\Temp\helloworld.proj”(默认目标)——失败。
生成失败。
“C:\Users\binki\AppData\Local\Temp\helloworld.proj”(默认目标)(1:2)->
(构建目标)->
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5):错误MSB4036:找不到“helloworld”任务。检查以下内容:1.)项目文件中任务的名称与任务类的名称相同。2.)任务类是“公共”的,并实现Microsoft.Build.Framework.ITask接口。3.)任务在项目文件中或位于“C:\Program files(x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64”目录中的*.tasks文件中正确声明。
0个警告
1个错误
时间流逝00:00:01.71