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

A source code nuget package defining a .cs.pp file fails to resolve the namespace if <RootNamespace> is not set in the project #39933

Open
vpenades opened this issue Apr 2, 2024 · 0 comments
Labels
Area-WebSDK untriaged Request triage from a team member

Comments

@vpenades
Copy link

vpenades commented Apr 2, 2024

Describe the bug

Originally posted here: NuGet/Home#13346

.cs.pp template files coming from a source code nuget package fail to evaluate the $rootnamespace$ macro in the .cs.pp files, because <RootNamespace> definition is missing in the csproj file.

To Reproduce

Create a source code package including a .cs.pp template file that uses namespace $rootnamespace$ ... or consume an existing source code nuget like CodeSugar.Sys.IO.Sources into a new project.

The test project referencing the nuget package does NOT have a <RootNamespace> property defined, so theoretically, the default assembly namespace should be used for $rootnamespace$

And what happens is this:

-At edition time, the files seem to be correctly evaluated with the correct namespace, and the files and classes are correctly found by intellisense within visual studio.
-At build time, it fails and gives errors saying that the templated files are missing due to (I guess) incorrectly resolving $rootnamespace$

If then, I add the <RootNamespace> to the test project, even if the namespace is the same as the default, then the project builds correctly.

So clearly, there's a problem at build time, the compiler is unable to resolve the root namespace if it's not explicitly defined using the <RootNamespace> property.

in code:

<project>

<PropertyGroup>
  <!-- <RootNamespace>DefaultAssemblyNamespace</RootNamespace> -->   <== if I comment this line, it fails to build
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="CodeSugar.Sys.IO.Sources" Version="1.0.0-Preview-20240326-110152" PrivateAssets="all" />
</ItemGroup>

</project>

Exceptions (if any)

Further technical details

  • Visual Studio Version 17.9.5
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-WebSDK untriaged Request triage from a team member labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-WebSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant