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

No types defined for elements in XSD schema #10983

Closed
eZprava opened this issue Nov 17, 2024 · 8 comments
Closed

No types defined for elements in XSD schema #10983

eZprava opened this issue Nov 17, 2024 · 8 comments

Comments

@eZprava
Copy link

eZprava commented Nov 17, 2024

Issue Description

In XSD there are many elements which should likely have type="xs:string", but they have no type at all, thus ur-type. Is it a bug, or a design choice?
E.g.:


<xs:element name="Name"> // Friendly display name (optional)

Steps to Reproduce

Expected Behavior

Actual Behavior

Analysis

No response

Versions & Configurations

No response

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Nov 17, 2024

The type of the item metadata elements cannot be just xs:string because at least the Condition attribute must be allowed, perhaps Label too. Syntax example:

<Project>
  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient">
      <VersionOverride Condition="$(TargetFramework) == 'netstandard2.0'">1.2.3</VersionOverride>
    </PackageReference>
  </ItemGroup>
</Project>

I'm not sure about whether MSBuild allows child elements in item metadata elements. It allows them in PropertyGroup/* elements; see GenericPropertyType in the schema.

@eZprava
Copy link
Author

eZprava commented Nov 17, 2024

So it could be type derived from string which allows any attribute? I don't understand why one would need child elements in e.g. Name.

@KalleOlaviNiemitalo
Copy link

Yeah, I don't think child elements are needed in Name metadata.

AFAIK, these schemata are intended for Intellisense and online help in the Visual Studio IDE. If the item metadata elements were given more restrictive types, then would that help for those purposes, or would the types be overridden by some Visual Studio feature anyway?

@eZprava
Copy link
Author

eZprava commented Nov 18, 2024

I don't know about VS - I used XSD to generate C# classes from Microsoft.Build.xsd and found out that Name is object instead of string. So I was curious if there's some deeper reason why one element has type="msb:boolean" while other has ur-type.

@KalleOlaviNiemitalo
Copy link

If you want to read, modify, and write MSBuild project files programmatically in C#, the MSBuild API has classes like Microsoft.Build.Construction.ProjectRootElement; see also MSBuildLocator.

On the other hand, if your program does not need to build those projects, and needs to tolerate future extensions to MSBuild project syntax even when neither the program itself nor any installed version of MSBuild supports them, then System.Xml APIs (including deserialisation) may be a better choice than the MSBuild API.

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Nov 18, 2024

The MSBuild XML schema files have targetNamespace="http://schemas.microsoft.com/developer/msbuild/2003", and when you generate C# source code from these schemas, I think XmlSerializer will then require this XML namespace. However, MSBuild itself does not require that namespace nowadays, and IIRC the project templates in .NET SDK do not have xmlns="http://schemas.microsoft.com/developer/msbuild/2003". This may make the XSD-generated code unusable for projects that were created from those templates.

The classes in the Microsoft.Build.Construction namespace do not have this problem.

@eZprava
Copy link
Author

eZprava commented Nov 18, 2024

Thanks, I'm not using XmlSerializer. I have my own library to generate C# classes and I used .NET Framework .csproj as test files, to see if it can be round-tripped using generated classes. I needed to add support for substitution groups, it's cleverly used in the schema, it was new to me. Now it works, I was just curious why the Name element has ur-type, that's all.

@maridematte
Copy link
Contributor

Team Triage: @KalleOlaviNiemitalo answer is correct, the types are there to feed into intellisense and extra VS functions. Let us know if you have any more questions regarding this, but closing the issue for now.

@maridematte maridematte closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
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

No branches or pull requests

3 participants