Mistakes generate winmdroot when Windows.Win32 not generated
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.5k
- Forks
- 124
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 9
Description
Actual behavior
When generate OverloadResolutionPriorityAttribute, it will add using winmdroot = global::Windows.Win32;:
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981,SYSLIB1092
using global::System;
using global::System.Diagnostics;
using global::System.Diagnostics.CodeAnalysis;
using global::System.Runtime.CompilerServices;
using global::System.Runtime.InteropServices;
using winmdroot = global::Windows.Win32;
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Specifies the priority of a member in overload resolution.
/// When unspecified, the default priority is 0.
/// </summary>
[global::System.AttributeUsage(global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
internal sealed class OverloadResolutionPriorityAttribute : global::System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="OverloadResolutionPriorityAttribute"/> class.
/// </summary>
/// <param name="priority">The priority of the attributed member. Higher numbers are prioritized, lower numbers are deprioritized. 0 is the default if no attribute is present.</param>
public OverloadResolutionPriorityAttribute(int priority)
{
this.Priority = priority;
}
/// <summary>
/// The priority of the member.
/// </summary>
public int Priority {
get; }
}
}
But when we do not generate any things under Windows.Win32, it will throw C:\Users\qq251\Downloads\GitHub\DotNetHost.Win32Metadata\DotNetHost.Win32Metadata.Test\obj\Debug\net4.8.1\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\Windows.Win32.OverloadResolutionPriorityAttribute.g.cs(16,27,16,34): error CS0400: 未能在全局命名空间中找到类型或命名空间名“Windows”(是否缺少程序集引用?)
Expected behavior
Do not generate using winmdroot = global::Windows.Win32; when not use it.
Repro steps
Use any 3d-part metadata which does not use any member under Windows.Win32.
Context
- CsWin32 version: 0.3.269
- Target Framework: net4.8.1
LangVersion(if explicitly set by project): latest
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with 3d-part metadata that uses no members under Windows.Win32, then inspect generation of Windows.Win32.OverloadResolutionPriorityAttribute.g.cs in the Microsoft.Windows.CsWin32.SourceGenerator output. The fix is complete when the generated file omits the winmdroot alias and the project compiles without the missing Windows namespace error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100