Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet build ignores casing of project file when setting up namespace #11217

Open
JanKrivanek opened this issue Jan 3, 2025 · 2 comments
Open

Comments

@JanKrivanek
Copy link
Member


Issue moved from dotnet/sdk#45701


From @NeilMacMullen on Friday, January 3, 2025 3:39:17 PM

Describe the bug

I'm not sure if this is a bug but it's certainly unexpected behaviour and caused me to waste a few hours yesterday....

dotnet build appears to use the casing of the csproj file specified in the command rather than the actual casing in the file-system. The practical impact of this is that the default-namespace for embedded resources is then incorrect and since GetManifestResourceStream is case-sensitive, applications can fail depending upon what casing was used when specifying dotnet build or dotnet publish

To Reproduce

The attached zip file contains a minimal example but the repro case is trivial...

  • create a simple console application whose name is a mixture of upper and lower case (e.g. MyApp)
  • Add an embedded resource (e.g. "testData.txt")
  • Use the following code for Program.cs
using System.Reflection;
var embedded = Assembly.GetExecutingAssembly().GetManifestResourceNames();
foreach(var m in embedded)
    Console.WriteLine($"embedded resource '{m}'");

Build the application with expected casing of the project file then all lower-case...

➜ rm -r -force bin ;rm -r -force obj; dotnet build .\MyApp.csproj;.\bin\Debug\net9.0\myapp.exe
Restore complete (0.2s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  MyApp succeeded (0.2s) → bin\Debug\net9.0\MyApp.dll

Build succeeded in 0.7s
embedded resource 'MyApp.testData.txt'

➜ rm -r -force bin ;rm -r -force obj; dotnet build .\myapp.csproj;.\bin\Debug\net9.0\myapp.exe
Restore complete (0.2s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  myapp succeeded (0.2s) → bin\Debug\net9.0\myapp.dll

Build succeeded in 0.7s
embedded resource 'myapp.testData.txt'

Note the difference in output - the resource path uses the casing specified in the build line.

Somewhat unexpectedly, dotnet run manages to use the correct casing...

➜ rm -r -force bin ;rm -r -force obj; dotnet run .\myapp.csproj
embedded resource 'MyApp.testData.txt'

MyApp.zip

Further technical details

.NET SDK:
 Version:           9.0.200-preview.0.24575.35
 Commit:            81b5f040be
 Workload version:  9.0.200-manifests.1e472b70
 MSBuild version:   17.13.0-preview-24569-04+8f6b8ad0a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.200-preview.0.24575.35\

.NET workloads installed:
 [android]
   Installation Source: SDK 9.0.200-preview.0, VS 17.13.35617.110, VS 17.12.35527.113
   Manifest Version:    35.0.24/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.24\WorkloadManifest.json
   Install Type:              Msi

 [aspire]
   Installation Source: SDK 9.0.200-preview.0, VS 17.12.35527.113
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

 [ios]
   Installation Source: SDK 9.0.200-preview.0, VS 17.13.35617.110, VS 17.12.35527.113
   Manifest Version:    18.2.9170/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.2.9170\WorkloadManifest.json
   Install Type:              Msi

 [maccatalyst]
   Installation Source: SDK 9.0.200-preview.0, VS 17.13.35617.110, VS 17.12.35527.113
   Manifest Version:    18.2.9170/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.2.9170\WorkloadManifest.json
   Install Type:              Msi

 [maui-windows]
   Installation Source: SDK 9.0.200-preview.0, VS 17.13.35617.110, VS 17.12.35527.113
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.0\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  8.0.111 [C:\Program Files\dotnet\sdk]
  8.0.206 [C:\Program Files\dotnet\sdk]
  8.0.307 [C:\Program Files\dotnet\sdk]
  8.0.404 [C:\Program Files\dotnet\sdk]
  9.0.101 [C:\Program Files\dotnet\sdk]
  9.0.200-preview.0.24575.35 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [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:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

@JanKrivanek
Copy link
Member Author


Issue moved from dotnet/sdk#45701


From @baronfel on Friday, January 3, 2025 3:58:21 PM

The default value for the RootNamespace is computed here:

<RootNamespace Condition=" '$(RootNamespace)' == '' ">$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>

We're using the MSBuild-engine-provided reserved property MSBuildProjectName, which is set

So my suspicion is that there's some missing normalization in MSBuild itself that could/should be done here. I think it's reasonable to expect the name of the file to be its on-disk name. @JanKrivanek / @rainersigwald any objections to moving this to dotnet/msbuild?

@yuehuang010
Copy link
Contributor

Might be related to #3665.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants