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

Strong name the assemblies in this package #1467

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AArnott
Copy link
Contributor

@AArnott AArnott commented Dec 26, 2024

Closes #520

Remaining issues

Strong naming requires that all referenced assemblies are also strong named. Failure to comply with this emits a warning from the C# compiler and an assembly load failure at runtime on .NET Framework.
This repo has references to a few assemblies that are not strong named. So to succeed at strong naming this repo, we must first get the upstream dependencies strong named:

  • CSC : warning CS8002: Referenced assembly 'EnumerableAsyncProcessor, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.
  • CSC : warning CS8002: Referenced assembly 'Sourcy.Core, Version=0.0.66.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.
  • CSC : warning CS8002: Referenced assembly 'trxparser, Version=0.5.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.

While some of these are only dependencies of tests, and the tests would not strictly need to be strong named for your users, your repo uses InternalsVisibleTo, and a strong named assembly is only allowed to use InternalsVisibleTo to other strong named assemblies. So if you expose internals to your tests, you have to strong name them too.

@thomhurst
Copy link
Owner

Sourcy and EnumerableAsyncProcessor are my libraries too so I can easily accept a pr to strong sign them and push out a new version of each. Trxparser isn't mine though.

This reduces the dependencies we need to get strong name signed down to just `EnumerableAsyncProcessor`.
Fortunately, no one in this repo uses InternalsVisibleTo to this project, or it would _have_ to be strong named.
This avoids warnings about non-strong named TUnit assemblies that come from previously published nuget packages.
Once strong named assemblies are published to nuget.org and that newer version is consumed in this cycle, we *can* start strong naming this project if desired.
@AArnott
Copy link
Contributor Author

AArnott commented Dec 26, 2024

I was able to filter the problem to just EnumerableAsyncProcessor, which thomhurst/EnumerableAsyncProcessor#134 will solve when merged and published.

Copy link
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Feb 13, 2025
@AArnott
Copy link
Contributor Author

AArnott commented Feb 13, 2025

The EnumerableAsyncProcessor issue is now resolved, but now we have two new ones (OneOf, and Vogen.SharedTypes) which I've added to the PR description.

@thomhurst
Copy link
Owner

The EnumerableAsyncProcessor issue is now resolved, but now we have two new ones (OneOf, and Vogen.SharedTypes) which I've added to the PR description.

They're only used in the test example project. They aren't part of any packages. Should be okay?

This eliminates the last two non-strong-named dependency warnings.
@AArnott
Copy link
Contributor Author

AArnott commented Feb 13, 2025

They're only used in the test example project. They aren't part of any packages. Should be okay?

That can make it OK, but if you have InternalsVisibleTo to that test assembly from a strong named project, then the test project must also be strong named. (aside: I have InternalsVisibleTo so bad... for several reasons).

In your case, it appears this restriction does not impact you, because you don't use IVT to this test project from a strong named project. Yay. I've pushed another update to remove the last two warnings.

@AArnott AArnott marked this pull request as ready for review February 13, 2025 17:17
@@ -13,6 +13,10 @@
<NoWarn>NU1507;NU1903;CS9107</NoWarn>
<BuildTransitivePath>buildTransitive/$(TargetFramework)/</BuildTransitivePath>
<BuildPath>build/netstandard2.0</BuildPath>

<SignAssembly>true</SignAssembly>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is in the targets file instead, you could do something like:

<SignAssembly>'$(IsLibraryPackage)' == 'true'</SignAssembly>

That variable is applied to the NuGet package projects, and everything else should remain unsigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least as of when the PR was new, some non-shipping projects did need to be signed because you had InternalsVisibleTo exposed to them. And as of yesterday when I refreshed the PR, I saw you still have IVT in use, though I didn't pay attention to which assemblies you exposed internals to.

If you feel confident that you don't use IVT from shipping to non-shipping assemblies, then yes, I can give your suggestion a try.

@thomhurst
Copy link
Owner

I've just refactored so the only main project IVT usage is Core > Engine

#1857

@AArnott
Copy link
Contributor Author

AArnott commented Feb 15, 2025

Alright then. I'll take another look.

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.

Strong Naming - Sign assembly with a key
2 participants