在.net核心控制台应用程序中使用.net类库时,项目构建失败 [英] Project build failed while using .net class library in .net core console application
问题描述
我有.Net Core 3.1控制台应用程序,它引用了作为参考添加的类库项目FxCore
.
类库csproj的<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472</TargetFrameworks>
我尝试将其更改为<TargetFrameworks>net45;</TargetFrameworks>
,但仍然遇到相同的错误.
I have .Net Core 3.1 console application which is referring to a class library project FxCore
which is added as a reference.
class library csproj has <TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472</TargetFrameworks>
I have tried changing it to <TargetFrameworks>net45;</TargetFrameworks>
, but still getting the same error.
我收到以下错误.,我尝试了清理->重建并重新打开Visual Studio 2019(版本16.5.2)
I am getting the below error., I have tried clean -> ReBuild, Reopen the visual studio 2019 (version 16.5.2)
1> ------构建开始:项目:FxCore,配置:调试任何CPU ------ 1> J:\ Test \ core \ fx-core \ FxCore.csproj(3,3):警告MSB4011:" C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Microsoft.Common.props 无法再次导入.它已经在"C:\ Program"中导入 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.props(40,3)". 这很可能是构建创作错误.此后的导入 将被忽略. 1> C:\ Program 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.targets(37,3): 警告MSB4011:" C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Bin \ Microsoft.CSharp.targets 无法再次导入.它已经在进口 "J:\ Test \ core \ fx-core \ FxCore.csproj(120,3)".这很可能是 生成创作错误.随后的导入将被忽略. 1> C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Bin \ Microsoft.Common.CurrentVersion.targets(2081,5): 警告MSB3245:无法解析此引用.找不到 程序集"FXEntity,版本= 1.0.1.12,文化=中性, ProcessorArchitecture = MSIL".检查以确保程序集存在于 磁盘.如果您的代码需要此引用,则可能会得到 编译错误. 1> FxCore-> J:\ Test \ core \ fx-core \ bin \ Debug \ FxCore.dll 1> J:\ Test \ core \ fx-core \ FxCore.csproj(3,3):警告MSB4011: " C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Microsoft.Common.props 无法再次导入.它已经在"C:\ Program"中导入 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.props(40,3)". 这很可能是构建创作错误.此后的导入 将被忽略. 1> C:\ Program 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.targets(37,3): 警告MSB4011:" C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Bin \ Microsoft.CSharp.targets 无法再次导入.它已经在进口 "J:\ Test \ core \ fx-core \ FxCore.csproj(120,3)".这很可能是 生成创作错误.随后的导入将被忽略. 1> J:\ Test \ core \ fx-core \ FxCore.csproj(3,3):警告MSB4011: " C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Microsoft.Common.props 无法再次导入.它已经在"C:\ Program"中导入 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.props(40,3)". 这很可能是构建创作错误.此后的导入 将被忽略. 1> C:\ Program 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.targets(37,3): 警告MSB4011:" C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Bin \ Microsoft.CSharp.targets 无法再次导入.它已经在进口 "J:\ Test \ core \ fx-core \ FxCore.csproj(120,3)".这很可能是 生成创作错误.随后的导入将被忽略. 1> J:\ Test \ core \ fx-core \ FxCore.csproj:警告NU1603:FxCore取决于 在Microsoft.Practices.ServiceLocation(> = 1.3.0)上,但是 找不到Microsoft.Practices.ServiceLocation 1.3.0.一个 Microsoft.Practices.ServiceLocation 1.4.11的近似最佳匹配 解决了. 1>完成的构建项目"FxCore.csproj". 1>完成的建筑物 项目"FxCore.csproj". 2> -------构建已开始:项目: CoreConsoleApp,配置:调试任何CPU ------ 2> J:\ Test \ core \ fx-core \ FxCore.csproj(3,3):警告MSB4011: " C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Microsoft.Common.props 无法再次导入.它已经在"C:\ Program"中导入 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.props(40,3)". 这很可能是构建创作错误.此后的导入 将被忽略. 2> C:\ Program 文件\ dotnet \ sdk \ 3.1.201 \ Sdks \ Microsoft.NET.Sdk \ Sdk \ Sdk.targets(37,3): 警告MSB4011:" C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Bin \ Microsoft.CSharp.targets 无法再次导入.它已经在进口 "J:\ Test \ core \ fx-core \ FxCore.csproj(120,3)".这很可能是 生成创作错误.随后的导入将被忽略. 2> C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ MSBuild \ Current \ Bin \ Microsoft.Common.CurrentVersion.targets(1655,5): 警告NU1702:ProjectReference'J:\ Test \ core \ fx-core \ FxCore.csproj' 已使用".NETFramework,Version = v4.6.1"而不是 项目目标框架'.NETCoreApp,Version = v3.1'.该项目可能 与您的项目不完全兼容. 2> J:\ Test \ core \ CoreConsoleApp \ Program.cs(2,7,2,9):错误CS0246: 找不到类型或名称空间名称"FX"(您是否缺少 使用指令还是程序集引用?) 2> J:\ Test \ core \ CoreConsoleApp \ Program.cs(7、24、7、32):错误CS0246: 类型或名称空间名称'FxCommon'找不到(您是否丢失了 使用指令还是程序集引用?)2>完成的建筑项目 "CoreConsoleApp.csproj"; - 失败的. ===========构建:1个成功,1个失败,0个最新,0个跳过==========
1>------ Build started: Project: FxCore, Configuration: Debug Any CPU ------ 1>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)". This is most likely a build authoring error. This subsequent import will be ignored. 1>C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets" cannot be imported again. It was already imported at "J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a build authoring error. This subsequent import will be ignored. 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "FXEntity, Version=1.0.1.12, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. 1>FxCore -> J:\Test\core\fx-core\bin\Debug\FxCore.dll 1>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)". This is most likely a build authoring error. This subsequent import will be ignored. 1>C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets" cannot be imported again. It was already imported at "J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a build authoring error. This subsequent import will be ignored. 1>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)". This is most likely a build authoring error. This subsequent import will be ignored. 1>C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets" cannot be imported again. It was already imported at "J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a build authoring error. This subsequent import will be ignored. 1>J:\Test\core\fx-core\FxCore.csproj : warning NU1603: FxCore depends on Microsoft.Practices.ServiceLocation (>= 1.3.0) but Microsoft.Practices.ServiceLocation 1.3.0 was not found. An approximate best match of Microsoft.Practices.ServiceLocation 1.4.11 was resolved. 1>Done building project "FxCore.csproj". 1>Done building project "FxCore.csproj". 2>------ Build started: Project: CoreConsoleApp, Configuration: Debug Any CPU ------ 2>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)". This is most likely a build authoring error. This subsequent import will be ignored. 2>C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets" cannot be imported again. It was already imported at "J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a build authoring error. This subsequent import will be ignored. 2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1655,5): warning NU1702: ProjectReference 'J:\Test\core\fx-core\FxCore.csproj' was resolved using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This project may not be fully compatible with your project. 2>J:\Test\core\CoreConsoleApp\Program.cs(2,7,2,9): error CS0246: The type or namespace name 'FX' could not be found (are you missing a using directive or an assembly reference?) 2>J:\Test\core\CoreConsoleApp\Program.cs(7,24,7,32): error CS0246: The type or namespace name 'FxCommon' could not be found (are you missing a using directive or an assembly reference?) 2>Done building project "CoreConsoleApp.csproj" -- FAILED. ========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
但是在Program.cs中,我可以使用代码,IntelliSense不会显示任何错误.
But in the Program.cs I am able to use the code, IntelliSense not showing any error.
using System;
using FX.Core;
namespace CoreConsoleApp
{
class Program
{
private static FxCommon _fxCommon = new FxCommon();
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
_fxCommon.Logger.LogWrite("hello");
}
}
}
由于这个原因,我无法运行控制台应用程序,请帮忙.
I am not able to run the console application due to this, please help.
推荐答案
.NET Core 不使用 .NET Framework(net###
)目标;它可以消耗netstandard*
和netcoreapp*
.
.NET Core doesn't consume .NET Framework (net###
) targets; it can consume netstandard*
and netcoreapp*
.
所以;您的FxCore
将需要定位/多定位.NET Standard或.NET Core之一.
So; your FxCore
is going to need to target/multi-target one of .NET Standard or .NET Core.
针对目标/多目标选择什么:
In terms of choice of what to target/multi-target:
- 目标
netstandard*
-如果您在实现中不需要任何特定于框架的内容 - 多目标
netcoreapp*
和netstandard*
-如果要在可用的情况下使用netcoreapp*
功能,否则,请使用下层通用实施方式 - 多目标
netcoreapp*
和net###
-如果实现完全是特定于平台的,并且不可能实现通用实现
- target
netstandard*
- if you don't need anything framework-specific in the implementation - multi-target
netcoreapp*
andnetstandard*
- if you want to usenetcoreapp*
features when they are available, or use a down-level common implementation otherwise - multi-target
netcoreapp*
andnet###
- if the implementations are completely platform specific and no common implementation is possible
(其中*
/###
是您选择的版本-当前可能是netstandard2.1
,netcoreapp3.1
和net472
/net48
)
(where *
/ ###
is your choice of versions - probably netstandard2.1
, netcoreapp3.1
and net472
/net48
at the current time)
这篇关于在.net核心控制台应用程序中使用.net类库时,项目构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!