使用.NET Core正确地包含一个项目

3
我正在尝试使用.NET Core编译一些C#代码。我的上次尝试被YamlDotNet不支持.NET Core所阻碍,但是这个问题已经解决了。
因此,我像这样设置了一个项目:
<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\..\YamlDotNet\YamlDotNet\YamlDotNet.csproj" />
  </ItemGroup>
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
  </PropertyGroup>
</Project>

我运行了:

dotnet restore

操作成功。接下来我尝试了:

dotnet build

这导致了以下错误:
/usr/share/dotnet/sdk/1.0.1/Microsoft.Common.CurrentVersion.targets(1111,5):
  error MSB3644: The reference assemblies for framework ".NETCoreApp,Version=v1.0"
  were not found. To resolve this, 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/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(92,5):
  error : Cannot find project info for '/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj'.
  This can indicate a missing project reference.
  [/work/yaml-editor/docker/src/dotnet/dotnet.csproj]

我正在使用官方的microsoft/dotnet:1.0-sdk Docker容器,因此我不明白为什么.NETCoreApp,Version=v1.0丢失了。我该如何修复错误?
更新:
我发现我必须配置<TargetFramework>netstandard1.3</TargetFramework>,这也存在于YamlDotNet.csproj中。然而,现在我得到了这个错误:
/usr/share/dotnet/sdk/1.0.1/Microsoft.CSharp.CurrentVersion.targets(133,9): warning MSB3884: Could not find rule set file "MinimumRecommendedRules.ruleset". [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Core/YamlException.cs(113,30): error CS0115: 'YamlException.GetObjectData(SerializationInfo, StreamingContext)': no suitable method found to override [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Core/YamlException.cs(112,26): error CS0234: The type or namespace name 'Permissions' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Core/YamlException.cs(112,57): error CS0234: The type or namespace name 'Permissions' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Core/YamlException.cs(112,112): error CS0246: The type or namespace name 'Flags' could not be found (are you missing a using directive or an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Core/YamlException.cs(112,120): error CS0234: The type or namespace name 'Permissions' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Serialization/Utilities/TypeConverter.cs(45,26): error CS0234: The type or namespace name 'Permissions' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Serialization/Utilities/TypeConverter.cs(45,52): error CS0234: The type or namespace name 'Permissions' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Serialization/Utilities/TypeConverter.cs(45,107): error CS0246: The type or namespace name 'Name' could not be found (are you missing a using directive or an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
Serialization/Utilities/TypeConverter.cs(47,54): error CS0234: The type or namespace name 'TypeConverter' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) [/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj]
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for '/work/yaml-editor/docker/YamlDotNet/YamlDotNet/YamlDotNet.csproj'. This can indicate a missing project reference. [/work/yaml-editor/docker/src/dotnet/dotnet.csproj]
make: *** [build/bin/dotnet-event] Error 1

我记得上一次尝试时也看到过类似的错误,但我不知道为什么它还会发生,因为YamlDotNet声称支持.NET Core。


@JoséPedro,那似乎与问题无关。已经更新了问题。 - flyx
尝试过了,没有帮助。 - flyx
你只能将项目称为Net Standard或Nuget Packages。Class Lib与.Net Core不兼容。 - Fals
@flyx,你可以这样做,但前提是它是 .Net Standard。更新后的错误指的是在 .Net Standard 1.3 上未实现的权限版本,你可以尝试升级到 v1.6,因为它有更多的内容被移植过来了。 - Fals
2
请升级到最新版本的.NET Core SDK。您正在使用的版本(1.0.1)已被1.1.0和2.0.0所取代。 - Martin Ullrich
显示剩余6条评论
1个回答

1

我曾经遇到过同样的错误,后来通过添加以下内容解决了问题:

using YamlDotNet.RepresentationModel;

尝试添加四个命名空间之一,看看哪一个可以使用:

using YamlDotNet.Serialization
using YamlDotNet.RepresentationModel
using YamlDotNet.Helpers
using YamlDotNet.Core

1
谢谢回答。恐怕这个项目早已过去,我无法验证是否是这个问题。 - flyx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接