Skip to content

fix dotnet run for example projects on a freshly-cloned repository#294

Merged
LittleLittleCloud merged 6 commits intoRazorConsole:mainfrom
Marcin-Lach:fix/dotnet-run-examples
Feb 8, 2026
Merged

fix dotnet run for example projects on a freshly-cloned repository#294
LittleLittleCloud merged 6 commits intoRazorConsole:mainfrom
Marcin-Lach:fix/dotnet-run-examples

Conversation

@Marcin-Lach
Copy link
Contributor

@Marcin-Lach Marcin-Lach commented Feb 1, 2026

Move EmitCompilerGeneratedFiles into SetCompilerGeneratedFilesPath target.

Without this, if you try to run any example on a freshly-cloned repo with dotnet run --project .\examples\FileExplorer\ --framework "net10.0", you will fail because of a missing folder

CSC : error CS0016: Could not write to output file 'C:\nonsynced\code\razorConsoleFork\artifacts\obj\RazorConsole.Core\Generated\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs' -- 'Could not find a part of the path 'C:\nonsynced\code\razorConsoleFork\artifacts\obj\RazorConsole.Core\Generated\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs'.'

...

CSC : error CS0016: Could not write to output file 'C:\nonsynced\code\razorConsoleFork\artifacts\obj\RazorConsole.Core\Generated\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\_Imports_razor.g.cs' -- 'Could not find a part of the path 'C:\nonsynced\code\razorConsoleFork\artifacts\obj\RazorConsole.Core\Generated\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\_Imports_razor.g.cs'.'

The build failed. Fix the build errors and run again.

@ParadiseFallen
Copy link
Collaborator

i can't reproduce

@Marcin-Lach
Copy link
Contributor Author

Marcin-Lach commented Feb 1, 2026

i can't reproduce

You can try going to a fresh branch, be sure you stash all changes, clean, try running example. It reproduces the issue for me all the time. If you still cannot reproduce, please share dotnet --info, maybe I'm missing something

git add -A
git stash
git switch main
git clean -dfx # be sure to not have any changes, since those will be wiped, do this a couple of times, until nothing more is removed
git clean -dfx #do this a couple of times
git clean -dfx #do this a couple of times
dotnet run --project ./examples/FileExplorer # be sure to have correct path, writing this on phone so might have incorrect syntax

@LittleLittleCloud
Copy link
Member

Feels like a misconfiguration on source generator target folder...

<Target Name="SetCompilerGeneratedFilesPath" BeforeTargets="PrepareForBuild" Condition="'$(Configuration)' == 'Debug'">

Could you share .binlog so we can see where the source generated code lives. The example project default to .net9 so I wonder if the generated code also lives under '.net10' folder instead of net10

@Marcin-Lach
Copy link
Contributor Author

Marcin-Lach commented Feb 2, 2026

Feels like a misconfiguration on source generator target folder...

<Target Name="SetCompilerGeneratedFilesPath" BeforeTargets="PrepareForBuild" Condition="'$(Configuration)' == 'Debug'">

Could you share .binlog so we can see where the source generated code lives. The example project default to .net9 so I wonder if the generated code also lives under '.net10' folder instead of net10

dotnet run --project .\examples\FileExplorer\ -bl:build-log.binlog --configuration "Debug"- this one runs flawlessly
dotnet run --project .\examples\FileExplorer\ -bl:build-log.binlog - this one fails on missing "artifacts\obj\RazorConsole.Core\Generated" folder. I did run git clean -dfx between the two to remove all untracked files and folders (artifacts folder was removed).

 dotnet --info
.NET SDK:
 Version:           10.0.102
 Commit:            4452502459
 Workload version:  10.0.100-manifests.73000c7b
 MSBuild version:   18.0.7+445250245

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.102\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      10.0.2
  Architecture: x64
  Commit:       4452502459

.NET SDKs installed:
  8.0.413 [C:\Program Files\dotnet\sdk]
  9.0.110 [C:\Program Files\dotnet\sdk]
  9.0.201 [C:\Program Files\dotnet\sdk]
  10.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  C:\code\razorConsoleFork\global.json

@LittleLittleCloud
Copy link
Member

LittleLittleCloud commented Feb 7, 2026

@Marcin-Lach I can reproduce, the command I run is

git clean -fdx
dotnet run --project examples\FileExplorer

It seems to because of the timing when Configuration is set to Debug by msbuild when its value is not provided. The Configuration Value is empty at the beginning so the EmitCompilerGeneratedFiles is false. It then be set to Debug by msbuild because of missing value, so SetCompilerGeneratedFilesPath sets the CompilerGeneratedFilesOutputPath . But SetCompilerGeneratedFilesPath didn't set EmitCompilerGeneratedFiles to true, so source generator doesn't get a chance to invoke, which cause the above error because CompilerGeneratedFilesOutputPath is not empty but Compiler Generated Files is missing.

The fix can be simply also set EmitCompilerGeneratedFiles to true in SetCompilerGeneratedFilesPath from the root Directory.Build.props.

@Marcin-Lach
Copy link
Contributor Author

@Marcin-Lach I can reproduce, the command I run is

git clean -fdx
dotnet run --project examples\FileExplorer

It seems to because of the timing when Configuration is set to Debug by msbuild when its value is not provided. The Configuration Value is empty at the beginning so the EmitCompilerGeneratedFiles is false. It then be set to Debug by msbuild because of missing value, so SetCompilerGeneratedFilesPath sets the CompilerGeneratedFilesOutputPath . But SetCompilerGeneratedFilesPath didn't set EmitCompilerGeneratedFiles to true, so source generator doesn't get a chance to invoke, which cause the above error because CompilerGeneratedFilesOutputPath is not empty but Compiler Generated Files is missing.

The fix can be simply also set EmitCompilerGeneratedFiles to true in SetCompilerGeneratedFilesPath from the root Directory.Build.props.

Overwritten the PR with your suggestion.
Ready for review

@LittleLittleCloud LittleLittleCloud merged commit c389d01 into RazorConsole:main Feb 8, 2026
6 checks passed
@github-actions github-actions bot added this to the v0.4.0 milestone Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants