Reputation: 53
I've tried to create a simple solution in .net5.0 with VSCode 1.52.0 on linux.
I've create 2 projects.
CLIConsole.csproj with 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();
}
}
}
and
MyLib.csproj, with MyClass.cs
using System;
namespace MyLib
{ public class MyClass
{
public void Test()
{
Console.WriteLine("This is a test");
}
}
}
When I run in debug mode, I have this error :
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
NB : When in my Program.cs, I don't use MyLib, the debug works
I'm on linux and debug doesn't work because my assembly is not found.
I've tried this same solution in debug mode on Windows (always with VSCode), every things works.
My 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}"
}
]
}
My tasks.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"
}
]
}
My 'dotnet --info' :
SDK .NET (reflétant tous les fichiers global.json) : Version:
5.0.100 Commit: 5044b93829Environnement d'exécution : OS Name: gentoo OS Version: OS Platform: Linux RID: gentoo-x64 Base Path:
/opt/dotnet_core/sdk/5.0.100/Host (useful for support): Version: 5.0.0 Commit: cf258a14b7
.NET SDKs installed: 5.0.100 [/opt/dotnet_core/sdk]
.NET runtimes installed: 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]To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
I don't know what to do, i am really blocked.
Thanks for your help !
Upvotes: 0
Views: 691
Reputation: 53
I've found a solution, but I don't understand why my previous config doesn't work.
With this in CLIConsole.csproj, debug works :
<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>
But with that, it doesn't work :
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\MyLib\MyLib.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
That is very strange...
Upvotes: 0