gpt4 book ai didi

c# - 正确包含一个带有 .NET 核心的项目

转载 作者:行者123 更新时间:2023-12-05 06:38:33 25 4
gpt4 key购买 nike

我正在尝试使用 .NET Core 编译一些 C# 代码。我的last attempt受到 YamlDotNet 不支持 .NET Core 的阻碍,但是 has changed .

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

<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。

最佳答案

我有同样的错误,我通过添加解决了这个错误:

using YamlDotNet.RepresentationModel;

尝试添加四个命名空间之一,看看哪个有效:

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

关于c# - 正确包含一个带有 .NET 核心的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45849027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com