[英]Alternate method in referenced assembly when in debug mode using [Conditional(“DEBUG”)]
[英]Local assembly not found in debug mode VSCode
我尝试在 linux 上使用 VSCode 1.52.0 在 .net5.0 中创建一个简单的解决方案。
我创建了 2 个项目。
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,版本=1.0.0.0,文化=中性,PublicKeyToken=null'
注意:在我的 Program.cs 中,我不使用 MyLib,调试工作
我在 linux 上,调试不起作用,因为找不到我的程序集。
我已经在 Windows(始终使用 VSCode)的调试模式下尝试了相同的解决方案,一切正常。
我的launch.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"
}
]
}
我的'dotnet --info':
SDK .NET (reflétant tous les fichiers global.json):版本:
5.0.100 提交:5044b93829执行环境:操作系统名称:gentoo 操作系统版本:操作系统平台:Linux RID:gentoo-x64 基本路径:
/opt/dotnet_core/sdk/5.0.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.App 5.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="..\MyLib\MyLib.csproj">
<HintPath>..\MyLib\bin\Debug\net5.0\MyLib.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
但是这样就行不通了:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\MyLib\MyLib.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
这很奇怪……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.