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.

When using full paths to source xaml files, the generated .g.cs files aren't placed in subfolders in the obj\target folder

See original GitHub issue

Version Used: Microsoft ® Visual C# Compiler version 4.0.1-1.21568.1 (6ab66011)

Steps to Reproduce:

  1. Create a .csproj. Using full pathnames, specify multiple xaml files with the same name, but a different subfolder.
    <Page Include="C:\Projects\MyProject\Views\View1\GeneralView.xaml">
      <Link>Views\View1\GeneralView.xaml</Link>
      <SubType>Designer</SubType>
    </Page>
    <Page Include="C:\Projects\MyProject\Views\View2\GeneralView.xaml">
      <Link>Views\View2\GeneralView.xaml</Link>
      <SubType>Designer</SubType>
    </Page>
  1. Build
  2. Build Fails. Observe CS2002 warnings, combined with other errors because only the last GeneralView.g.cs file was written to /obj/x64/Debug

Expected Behavior: Each GeneralView.g.cs file should be in a subfolder in the object folder. /obj/x64/Debug/Views/View1/GeneralView.g.cs /obj/x64/Debug/Views/View2/GeneralView.g.cs

Actual Behavior: Each GeneralView.g.cs file overwrites the previous file in the root object folder, so you end up with only the last one in the root object folder: /obj/x64/Debug/GeneralView.g.cs

Notes: The distinction is that the csproj file is using full paths to the source files, instead of relative paths. I’m using cmake in my project, and it generated the csproj files like this. I would file a bug with cmake, but there doesn’t seem to be anything in the specification for csproj files that would preclude using full paths to source files.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
emusgravecommented, Mar 22, 2022

@lindexi I agree that not many will use absolute paths, because they would have to be writing the csproj by hand. Or, in this case, using cmake to generate it. But anyone using cmake and also having duplicate file names with encounter this. Cmake is designed to always support out-of-source builds, so there is no way around the absolute paths.

My workaround was to guarantee that each file has a unique name, so they don’t conflict when they all get written to the same output folder.

Perhaps an error message could at least be generated by the compiler when it encounters a duplicate file name during a single build run (as it tries to write the output)?

0reactions
lindexicommented, Mar 22, 2022

And I think few developers will write absolute paths in projects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When using full paths to source xaml files, the generated .g ...
When using full paths to source xaml files, the generated .g.cs files aren't placed in subfolders in the obj\target folder #6290.
Read more >
Error in a .g.cs file?
Try doing a clean. If that doesn't work, delete the bin obj directories in your solution, then do a full rebuild.
Read more >
A fix for CS0426 in XAML and generated .g.cs file while ...
While working on a project I started debugging and out of no where a bunch of CS0426 errors came out of nowhere in...
Read more >
C# XAML files with the same name in different directories ...
It seems that if we have 2 xaml files with the same name but under different folders and namespaces, when they get converted...
Read more >
RazorFile_razor.g.cs is missing : r/Blazor
cs files in my Bin or Obj folders for my blazor WASM project. is there something that needed in the project file or...
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