gpt4 book ai didi

.net - 构建针对完整 .NET Framework 4.6.2 的默认 .NET Core 控制台应用程序时出错

转载 作者:行者123 更新时间:2023-12-02 07:46:44 25 4
gpt4 key购买 nike

我一直在尝试使用 .NET Core CLI 工具学习 .NET Core 编程的基础知识。我下载了适用于 Windows 版本 1.0.1 的 .NET Core SDK,并按照下载页面上的简单说明进行操作 ( https://www.microsoft.com/net/core#windows ):

mkdir hwapp
cd hwapp
dotnet new
dotnet restore
dotnet run

这可以在我的 Windows 10 x64 计算机上编译并正常运行。

当我尝试在同一应用程序中定位 .NET Framework 4.6.2 时,我遇到了麻烦。根据我所读到的内容,我应该只需要在“frameworks”节点下添加一个值为“net462”的节点:

{
"net462": {}
}

但是,添加此节点后,运行 dotnet Restore,然后运行 ​​dotnet build CLI 命令,出现以下错误:

Project hwapp (.NETFramework,Version=v4.6.2) will be compiled because expected outputs are missing
Compiling hwapp for .NETFramework,Version=v4.6.2
C:\Program Files\dotnet\dotnet.exe compile-csc @C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.rsp returned Exit Code 1
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(2,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(3,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(4,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(5,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(2,58): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(3,54): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(4,67): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(5,62): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\Program.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\Program.cs(5,18): error CS0518: Predefined type 'System.Object' is not defined or imported
C:\Development\dotNet\hwapp\Program.cs(7,33): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\Program.cs(7,23): error CS0518: Predefined type 'System.Void' is not defined or imported

Compilation failed.
0 Warning(s)
12 Error(s)

正如您从输出中可以看到的那样,当以 .NET Framework 4.6.2 为目标时,编译器似乎无法找到 System 命名空间。当我尝试定位较早的 .NET Framework(例如 4.6.1 和 4.5.2)时,也会出现同样的错误。

我尝试将 x64 版本的 System.dll 和 mscorlib.dll 的副本从 GAC 移动到 C:\Program Files\dotnet\目录,以便 csc.exe 程序可以找到系统命名空间,但没有成功.

如果有帮助,请在下面找到我的project.json 文件的内容:

{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"net462": {},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

任何帮助将不胜感激!

最佳答案

如果您想以.Net 4.6.2为目标,则需要安装.NET Framework 4.6.2 Developer Pack .

关于.net - 构建针对完整 .NET Framework 4.6.2 的默认 .NET Core 控制台应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40146086/

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