Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

The source generator was ignoring the RootNamespace property in .csproj files, always using the assembly name for the generated R class namespace instead.

Changes

MSBuild Integration

  • Added RootNamespace to CompilerVisibleProperty in LuYao.ResourcePacker.MSBuild.props to expose the property to source generators

Source Generator

  • Modified GetRootNamespace() to read build_property.RootNamespace from AnalyzerConfigOptionsProvider
  • Falls back to assembly name when RootNamespace is not set

Verification

  • Added samples/RootNamespaceTest demonstrating the fix with RootNamespace=Popcorn.Toolkit

Example

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <RootNamespace>Popcorn.Toolkit</RootNamespace>
    <ResourcePackerEnabled>true</ResourcePackerEnabled>
  </PropertyGroup>
</Project>

Generated code now correctly uses the specified namespace:

namespace Popcorn.Toolkit  // Previously would be assembly name
{
    internal static class R
    {
        public static class Keys { ... }
        public static ResourcePackageReader Reader { get; }
    }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>源生成器没有正确识别 RootNamespace 属性</issue_title>
<issue_description>当在 .csproj 文件中设定 RootNamespace 属性后,SG 项目生成的 R 类型所在命名空间没有遵循该属性,仍为程序集名称。

比如:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFramework>net8.0</TargetFramework>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<RootNamespace>Popcorn.Toolkit</RootNamespace>
	</PropertyGroup>

</Project>

生成的代码:

// <auto-generated />
#nullable enable

using System;
using System.IO;
using LuYao.ResourcePacker;

namespace Popcorn.Toolkit.Client
{
    /// <summary>
    /// Provides strongly-typed access to resources in Popcorn.Toolkit.Client.
    /// </summary>
    internal static class R

请创建一个项目用来验证、测试。项目存放在 samples 目录,并加入解决方案。</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 26, 2025 13:40
… project

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix source generator not recognizing RootNamespace property Fix: Source generator respects RootNamespace MSBuild property Oct 26, 2025
Copilot AI requested a review from Soar360 October 26, 2025 13:47
Copilot finished work on behalf of Soar360 October 26, 2025 13:47
@Soar360 Soar360 marked this pull request as ready for review October 26, 2025 13:47
@Soar360 Soar360 merged commit 2a801be into main Oct 26, 2025
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.

源生成器没有正确识别 RootNamespace 属性

2 participants