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

Dependency on System.Drawing.Common (>= 7.0.0) blocks latest Microsoft.Build package #8962

Closed
theolivenbaum opened this issue Jun 27, 2023 · 14 comments · Fixed by #9055
Closed
Assignees
Labels
Area: Engine Issues impacting the core execution of targets and tasks. Iteration:2023July triaged
Milestone

Comments

@theolivenbaum
Copy link

Not sure if this is the right place to report this, but while trying to update the Microsoft.Build package on our software to the latest version, we hit an issue due to a dependency on System.Security.Permissions, chianing to System.Windows.Extensions, which depends on System.Drawing.Common >= 7.0.0.

As System.Drawing.Common >=7.0.0 doesn't support macOS / Linux anymore (6.0.0 being the latest version that supports it through a compatibility flag), this chain of dependency blocks using to the latest package on Linux & macOS builds.

Any ideas if it is possible to force using the older package, or if the dependency version on System.Windows.Extensions could be lowered to >=6.0.0 ?

Thanks!

@ghost ghost added the untriaged label Jun 27, 2023
@ghost
Copy link

ghost commented Jun 27, 2023

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

Not sure if this is the right place to report this, but while trying to update the Microsoft.Build package on our software to the latest version, we hit an issue due to a dependency on System.Security.Permissions, chianing to System.Windows.Extensions, which depends on System.Drawing.Common >= 7.0.0.

As System.Drawing.Common >=7.0.0 doesn't support macOS / Linux anymore (6.0.0 being the latest version that supports it through a compatibility flag), this chain of dependency blocks using to the latest package on Linux & macOS builds.

Any ideas if it is possible to force using the older package, or if the dependency version on System.Windows.Extensions could be lowered to >=6.0.0 ?

Thanks!

Author: theolivenbaum
Assignees: -
Labels:

area-Infrastructure-libraries, untriaged

Milestone: -

@theolivenbaum theolivenbaum changed the title Nuget package dependency on System.Drawing.Common (>= 7.0.0) causes issues on macOS / Linux builds Dependency on System.Drawing.Common (>= 7.0.0) blocks latest Microsoft.Build package Jun 27, 2023
@ViktorHofer ViktorHofer transferred this issue from dotnet/runtime Jun 27, 2023
@rainersigwald rainersigwald added needs-triage Have yet to determine what bucket this goes in. and removed untriaged labels Jun 27, 2023
@rainersigwald
Copy link
Member

I don't think it'll be possible to pin to a specific older version forever; we try to track the latest versions available where possible.

Do you need to update your MSBuild reference? You shouldn't generally need to, since you generally load MSBuild from a .NET SDK that contains all of its dependencies.

@baronfel and I looked into dropping the dependency, which is almost doable, except for

|| e is XmlSyntaxException

@danmoseley
Copy link
Member

danmoseley commented Jun 27, 2023

If it's literally just that line, could you check the exception type dynamically - GetType()? Presumably this is an exceptional path. And you already depend on reflection.

@theolivenbaum
Copy link
Author

@rainersigwald we would love to drop the dependency on System.Drawing.Common 6.0.0, but due to how the deprecation was managed (i.e. as a breaking change including dropping support for the compatibility flag with the 7.0.0 release), we're stuck with 6.0.0 till other libraries replace their usage with other drawing libraries. While this is slowly moving forward, there are still many that have not yet updated, which forces us to use the last version that works cross platform.

I asked just because I found it very surprising that this dependency was there in the first place, and it seems it should be possible to either drop or change the constraint back to 6.0.0.

As shown in dotnet/sdk#33472, this is might also an issue when using the latest MSBuild package on other platforms, as System.Drawing.Common >= 7.0.0 is not available there.

@KalleOlaviNiemitalo
Copy link

https://source.dot.net/#System.Security.Permissions/System/Security/XmlSyntaxException.cs,64bad675b08e83cd,references doesn't list anything that creates an instance of XmlSyntaxException, and the constructor is obsolete in .NET 8 since dotnet/runtime#84383. Does MSBuild really have to recognize this type?

@danmoseley
Copy link
Member

tagging @ericstj for thoughts as he's very familiar with unexpected dependencies on System.Drawing

@rainersigwald
Copy link
Member

we would love to drop the dependency on System.Drawing.Common 6.0.0, but due to how the deprecation was managed (i.e. as a breaking change including dropping support for the compatibility flag with the 7.0.0 release), we're stuck with 6.0.0 till other libraries replace their usage with other drawing libraries. While this is slowly moving forward, there are still many that have not yet updated, which forces us to use the last version that works cross platform.

To be clear, I'm asking if you need to update your MSBuild reference, @theolivenbaum.

@theolivenbaum
Copy link
Author

Need: probably not now, although we've always tracked the latest version as well and were surprised to see it break this time.

@ericstj
Copy link
Member

ericstj commented Jun 28, 2023

In 8.0 we removed some of the dependencies on System.Drawing.Common but we did not remove the dependency originating from System.Security.Permissions since we discourage the use of System.Security.Permissions. The dependency from System.Security.Permissions to System.Windows.Extensions is required - for types in the public surface area. The dependency between System.Windows.Extensions to System.Drawing.Common is only for forwarded types, and one that @ViktorHofer and I have discussed removing. I put up a PR to do this. dotnet/runtime#88157

It think it would be a good idea to have MSBuild avoid it's dependency on System.Security.Permissions entirely. The runtime doesn't ever throw a XmlSyntaxException and I couldn't find a place where this is thrown elsewhere in the SDK. Perhaps on .NETFramework it's still thrown - but you wouldn't need a System.Security.Permissions reference there since it's part of mscorlib. Maybe you can just ifdef this code to only be present for NETFramework builds and then remove the package reference entirely.

Finally a question for the OP - @theolivenbaum - does your product actually need to deploy Microsoft.Build and it's dependency closure? Usually MSBuild as not a local dependency of an application. For example - a common usage in tasks would have Microsoft.Build referenced with PrivateAssets="All" with the expectation that the library be provided by the host when the task is loaded by MSBuild . You might be able to separate your usage of Microsoft.Build from the component that needs to use System.Drawing.Common and avoid leaking the Microsoft.Build dependencies to other projects by making it with PrivateAssets.

@KalleOlaviNiemitalo
Copy link

In .NET Framework, XmlSyntaxException can be thrown by internal classes System.Security.SecurityDocument, System.Security.Util.Parser, or System.Security.Util.Tokenizer. These are apparently used for deserializing Code Access Security types such as System.Security.PermissionSet, in AppDomain.Deserialize. Perhaps the runtime calls that when parsing security attributes from assemblies (ECMA-335 6th ed. §II.22.11 DeclSecurity).

The System.Security.SecurityElement.Escape(string) method has sometimes been used for general XML escaping unrelated to security, but that one does not throw XmlSyntaxException.

@rainersigwald
Copy link
Member

Maybe you can just ifdef this code to only be present for NETFramework builds and then remove the package reference entirely.

Works for me, let's do that.

@KirillOsenkov
Copy link
Member

KirillOsenkov commented Feb 5, 2024

What about the idea to check for the type dynamically, such as e != null && e.GetType.FullName == "System.Security.XmlSyntaxException"? Would love to drop that reference for .NET Framework too.

@theolivenbaum
Copy link
Author

Finally a question for the OP - @theolivenbaum - does your product actually need to deploy Microsoft.Build and it's dependency closure? Usually MSBuild as not a local dependency of an application. For example - a common usage in tasks would have Microsoft.Build referenced with PrivateAssets="All" with the expectation that the library be provided by the host when the task is loaded by MSBuild . You might be able to separate your usage of Microsoft.Build from the component that needs to use System.Drawing.Common and avoid leaking the Microsoft.Build dependencies to other projects by making it with PrivateAssets.

Thanks for the tip, I'll investigate on our end. If I remember correctly, it is pulled on our build via a dependency on our C# to JS transpiler.

@rainersigwald
Copy link
Member

If I remember correctly, it is pulled on our build via a dependency on our C# to JS transpiler.

That explicitly disables the hint from the MSBuildLocator package that tries to guide you to the approach @ericstj was suggesting (which I endorse). Looking at history it's been like that for a while. If y'all run into trouble removing that please file a new issue here--this is hard and we'd love to make it easier.

@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Engine Issues impacting the core execution of targets and tasks. Iteration:2023July triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants