首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >正确地包含一个具有.NET核心的项目

正确地包含一个具有.NET核心的项目
EN

Stack Overflow用户
提问于 2017-08-23 20:48:47
回答 1查看 828关注 0票数 3

我正在尝试用C#内核编译一些.NET代码。我的最后一次尝试受到了YamlDotNet不支持.NET核心,而是支持变了的阻碍。

所以,我设立了这样一个项目:

代码语言:javascript
运行
复制
<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>

我跑了:

代码语言:javascript
运行
复制
dotnet restore

那是成功的。然后我试着:

代码语言:javascript
运行
复制
dotnet build

这导致以下错误:

代码语言:javascript
运行
复制
/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码头容器,所以我不明白为什么.NETCoreApp,Version=v1.0会丢失。我怎样才能纠正错误?

更新:

我发现我必须配置<TargetFramework>netstandard1.3</TargetFramework>,这也存在于YamlDotNet.csproj中。然而,现在我得到了这个错误:

代码语言:javascript
运行
复制
/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核心。

EN

回答 1

Stack Overflow用户

发布于 2022-06-13 23:20:17

我也犯了同样的错误,我通过添加:

代码语言:javascript
运行
复制
using YamlDotNet.RepresentationModel;

尝试添加四种命名空间中的一种,并查看哪种名称空间有效:

代码语言:javascript
运行
复制
using YamlDotNet.Serialization
using YamlDotNet.RepresentationModel
using YamlDotNet.Helpers
using YamlDotNet.Core
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45849027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档