question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API-using application is spawned instead of `dotnet` when using CodeTaskFactory

See original GitHub issue

I’m trying to open csproj files via Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenProjectAsync from my console app. One of the projects, a rather big one, hangs the execution and spawns another instance of the app.

Tried both v4.6.0 from nuget.org and built myself from https://github.com/dotnet/roslyn/releases/tag/Visual-Studio-2022-Version-17.6.4, same behavior.

Tried to debug but quickly got lost… My best guess is that MSBuild is trying to create additional processes (for compilation?) to parallelize since it’s a large project, but instead instantiates my app. Any suggestions much appreciated.

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
GangWang01commented, Aug 16, 2023

Attached a sample ReproSample.zip to repro this issue.

For .NET version of msbuild, root cause is the following code couldn’t set dotnet cli path correctly when running the application via application.exe. Rather than the path of dotnet.exe, it’s wrongly set using the path of the applicaiton. https://github.com/dotnet/msbuild/blob/3050e91563b2b9bbafd820f4e8cd3d050dd9d21a/src/Tasks/RoslynCodeTaskFactory/RoslynCodeTaskFactoryCompilers.cs#L16-L18 For the repro sample, the fix is to modify dotnet cli path based on the environment variable MSBUILD_EXE_PATH that is set when registering the .NET SDK instance. But Roman mentioned getting dotnet cli path from the environment variable is not reliable and may not work for all scenarios, like Visual Studio doesn’t need to register the instance (Cc @rokonec, please correct me if anything wrong). Welcome suggestions on a good way to get dotnet cli path working for all scenarios.

As for .NET framework version of msbuild, the System.MissingMethodException with the meesage Method not found: ‘System.ReadOnlySpan1<Char> Microsoft.IO.Path.GetFileName(System.ReadOnlySpan1<Char>)’ is thrown out from https://github.com/dotnet/msbuild/blob/ec8b4a4eddeef899e427c77e4744f9fdb15fe3e8/src/Shared/FileMatcher.cs#L1650-L1651. This is related to https://github.com/dotnet/msbuild/issues/7873.

1reaction
Leon99commented, Jul 20, 2023

Running it using dotnet application.dll helps, thanks for the workaround and the explanation @rainersigwald!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to spawn a new Process to invoke a .net core console ...
I have a .net core console application named ShowDate . using System; namespace ShowDate { class Program { ...
Read more >
Error MSB4801: The task factory "CodeTaskFactory" is not ...
Your UsingTask is trying to use .Net Framework which is not available. Update the UsingTask to use the RoslynCodeTaskFactory in place of the ......
Read more >
MSBuild Inline Tasks with RoslynCodeTaskFactory
Learn about MSBuild RoslynCodeTaskFactory, which uses the cross-platform Roslyn compilers to generate in-memory task assemblies for use as ...
Read more >
ASP.NET Web APIs | Rest APIs with .NET and C#
Build secure REST APIs with C# that reach a broad range of clients, including browsers and mobile devices. Build and deploy on Linux,...
Read more >
dotnet run command - .NET CLI
The dotnet run command provides a convenient option to run your application from the source code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found