我尝试在linux上使用VSCode 1.52.0在.net5.0中创建一个简单的解决方案。
我创建了两个项目。
-
CLIConsole.csproj与Program.cs
using System; using MyLib; namespace CLIConsole { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); var mc = new MyClass(); mc.Test(); } } }
和
-
MyLib.csproj,带有MyClass.cs
using System; namespace MyLib { public class MyClass { public void Test() { Console.WriteLine("This is a test"); } } }
当我在调试模式下运行时,我会出现以下错误:
未处理的异常。System.IO.FileNotFoundException:无法加载文件或程序集'MyLib,版本=1.0.0.0,区域性=中性,PublicKeyToken=null'。系统找不到指定的文件。
文件名:'MyLib,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'
注意:在我的Program.cs中,我不使用MyLib,调试工作是
我在linux上,调试不起作用,因为找不到我的程序集。
我在Windows的调试模式下尝试过同样的解决方案(总是使用VSCode(,一切都正常。
我的启动json:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/CLIConsole/bin/Debug/net5.0/CLIConsole.dll",
"args": [],
"cwd": "${workspaceFolder}/CLIConsole",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
我的任务.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CLIConsole/CLIConsole.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/CLIConsole/CLIConsole.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/CLIConsole/CLIConsole.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
我的"网络信息":
SDK.NET(reflétant tous les fichiers global.json(:版本:
5.0.100提交:5044b93829环境:操作系统名称:gentoo操作系统版本:操作系统平台:Linux RID:gentoo-x64基本路径:
/opt/dotnet_core/sdk/50.100/主机(用于支持(:版本:5.0.0提交:cf258a14b7
已安装.NET SDK:5.0.100[/opt/dotnet_core/sdk]
已安装.NET运行时:Microsoft.AspNetCore.App 5.0.0[/opt/dotnet_core/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App5.0.0[/opt/dotnet_core/shared/Microsoft.NETCore.App]要安装其他.NET运行时或SDK:
https://aka.ms/dotnet-download
我不知道该怎么办,我真的被阻止了。
谢谢你的帮助!
我找到了一个解决方案,但我不明白为什么我以前的配置不起作用。
在CLIConsole.csproj中有了这个,调试工作就完成了:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Reference Include="..MyLibMyLib.csproj">
<HintPath>..MyLibbinDebugnet5.0MyLib.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
但有了这个,它就不起作用了:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..MyLibMyLib.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
这很奇怪。。。