.NET Core Tools: MSB3644 when importing a project

2019-05-22 12:51发布

问题:

I made a docker container based on microsoft/dotnet:1.0-sdk. Following the guide, I executed dotnet new console and got a file dotnet.csproj. dotnet restore and dotnet run worked.

Now I wanted to add my real code, which depends on YamlDotNet. So I edited the project file like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Yaml2Events.cs"/>
  </ItemGroup>
  <Import Project="..\..\YamlDotNet\YamlDotNet\YamlDotNet.csproj"/>
</Project>

..\..\YamlDotNet is the path where YamlDotNet is checked out to. Please do not comment about using a NuGet package or something, I want to have the latest version.

Now when I try to dotnet run, I get this error:

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.targets(40,3): warning MSB4011: "/usr/share/dotnet/sdk/1.0.1/Microsoft.CSharp.targets" cannot be imported again. It was already im
ported at "/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj (364,3)". This is most likely a build authoring error. This subsequent import will be ignored. [/work/yaml-editor
/docker/src/dotnet/dotnet.csproj]
/usr/share/dotnet/sdk/1.0.1/Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. To resolve th
is, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that
 assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework
you intend. [/work/yaml-editor/docker/src/dotnet/dotnet.csproj]

The build failed. Please fix the build errors and run again.

I guess this happens because in YamlDotNet.csproj, there's this line:

<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>

And based on the error, I guess this version is not available, so I need to patch the file. I simply removed the line, which made the error change to:

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.targets(40,3): warning MSB4011: "/usr/share/dotnet/sdk/1.0.1/Microsoft.CSharp.targets" cannot be imported again. It was already im
ported at "/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj (363,3)". This is most likely a build authoring error. This subsequent import will be ignored. [/work/yaml-editor
/docker/src/dotnet/dotnet.csproj]
/usr/share/dotnet/sdk/1.0.1/Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.0" were not found. To resolve th
is, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that
 assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework
you intend. [/work/yaml-editor/docker/src/dotnet/dotnet.csproj]

The build failed. Please fix the build errors and run again.

Now I am at a loss. I don't know where the reference to ".NETFramework,Version=v4.0" comes from, I do not find it in the YamlDotNet.csproj. Also, I get the feeling that I am doing something fundamentally wrong, because I should not need to modify another project file just to be able to import it, right?

So, what's the proper way to import an existing project to mine with the .NET core tools?