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

Arcade targets override AssemblyOriginatorKeyFile #2321

Open
Tracked by #2053
sbomer opened this issue Mar 22, 2019 · 16 comments
Open
Tracked by #2053

Arcade targets override AssemblyOriginatorKeyFile #2321

sbomer opened this issue Mar 22, 2019 · 16 comments
Milestone

Comments

@sbomer
Copy link
Member

sbomer commented Mar 22, 2019

When using arcade to publish a project that sets AssemblyOriginatorKeyFile, StrongName.targets overrides the key file (because arcade imports set a default value for StrongNameKeyId):

<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)snk/35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>

I believe StrongName.targets should not be setting properties as this violates the convention that static properties are computed in props files. Maybe this logic should be moved to StrongName.props, which would allow my project's setting of AssemblyOriginatorKeyFile to take precedence.

I can work around this by:

  • setting StrongNameKeyId in my project to some unknown string, preventing arcade's override, and
  • setting PublicKey and PublicKeyToken to some unknown string to satisfy the check in
    <Error Condition="'$(SignAssembly)' != 'false' and
    ('$(PublicKey)' == '' or '$(PublicKeyToken)' == '' or '$(AssemblyOriginatorKeyFile)' == '')"

I may have missed something, but I couldn't find any place where PublicKey or PublicKeyToken were actually used, so I think those shouldn't be required to be set in the first place. edit: they're used in the arcade InternalsVisibleTo generator - see below.

@sbomer
Copy link
Member Author

sbomer commented Mar 22, 2019

By the same reasoning, it seems like StrongName.targets also shouldn't be overriding DelaySign or PublicSign in

<PropertyGroup Condition="'$(SignAssembly)' != 'false'">
<DelaySign>false</DelaySign>
<PublicSign>true</PublicSign>
</PropertyGroup>

sbomer added a commit to sbomer/linker that referenced this issue Mar 22, 2019
@tmat
Copy link
Member

tmat commented Mar 22, 2019

Maybe this logic should be moved to StrongName.props, which would allow my project's setting of AssemblyOriginatorKeyFile to take precedence.

Why do you need to set AssemblyOriginatorKeyFile in your project? You should be just setting StrongNameKeyId and not to an unknown string but to one of the keys provided by Arcade. Do you need to use a key that's not available in Arcade?

@tmat
Copy link
Member

tmat commented Mar 22, 2019

I see you need to use Cecil's key. Does that snk file have public & private key pair?

@tmat
Copy link
Member

tmat commented Mar 22, 2019

setting PublicKey and PublicKeyToken to some unknown string

This will break InternalsVisibleTo generator if you use it in your project. I'd recommend you actually setting the correct values for these properties to avoid future surprises that something doesn't work. The checks are there for a reason.

@tmat
Copy link
Member

tmat commented Mar 22, 2019

Setting StrongNameKeyId to empty value is ok as long as you set PublicKey, PublicKeyToken and AssemblyOriginatorKeyFile yourself. This means you are not choosing to use any of the Arcade provided keys.

@sbomer
Copy link
Member Author

sbomer commented Mar 22, 2019

This will break InternalsVisibleTo generator if you use it in your project.

Thanks, that's what I was missing when I was trying to figure out what these properties were for. We don't use this, but I'll set the PublicKey and PublicKeyToken in case we ever do.

sbomer added a commit to sbomer/linker that referenced this issue Mar 27, 2019
@markwilkie
Copy link
Member

@sbomer - anything more to do here?

@sbomer
Copy link
Member Author

sbomer commented Mar 29, 2019

@markwilkie, updated the original issue to remove my comment about PublicKey/PublicKeyToken. The rest of it still applies - I believe arcade should be setting these properties in a .props file so that they don't override project files.

@tmat
Copy link
Member

tmat commented Mar 29, 2019

I believe arcade should be setting these properties in a .props file so that they don't override project files.

The intent here is to override the project settings if the projects sets StrongNameKeyId (the gotcha is that we set StrongNameKeyId be default, so the project actually need to set it to empty value). Perhaps we could report an error that the project sets both AssemblyOriginatorKeyFile and StrongNameKeyId.
I think we also discussed not setting StrongNameKeyId by default and require the project to set it to some value (including custom which would indicate it uses custom public key, not one that is predefined by Arcade). We can do that as well.

@markwilkie
Copy link
Member

Thoughts @sbomer ?

(also cc'ing @JohnTortugo )

@sbomer
Copy link
Member Author

sbomer commented Apr 11, 2019

@markwilkie Sorry for the delayed response. My angle is that it should be easy as possible for an existing SDK project to start using arcade (and it definitely shouldn't require digging through arcade targets to come up with a workaround). Maybe that's not really a design goal, in which case feel free to close this.

In my mind StrongNameKeyId is an arcade replacement for AssemblyOriginatorKeyFile that has a bit of extra functionality (automatically sets properties used for the InternalsVisibleTo generator). This replacement should either be opt-in, or have an easy opt-out for projects that want to stick with AssemblyOriginatorKeyFile without using the InternalsVisibleTo generator.

I'm guessing that making it opt-in is more work than it's worth at this point, because presumably lots of arcade projects are already using the default StrongNameKeyId.

So maybe a blend of @tmat's suggestions would provide a nice opt-out. You could set StrongNameKeyId by default as you do today, and support an option (either a 'custom' key id or another property) that doesn't require the project to set PublicKey and PublicKeyToken. Any error should point folks to the right opt-out.

@tmat
Copy link
Member

tmat commented Apr 11, 2019

You can set StrongNameKeyId to custom already to opt-out. The one thing that's missing is the error reporting that will tell you to do so.

@tmat
Copy link
Member

tmat commented Apr 11, 2019

My angle is that it should be easy as possible for an existing SDK project to start using arcade

That is the goal. :)

@markwilkie
Copy link
Member

@sbomer - should I assume you're waiting for error reporting before closing this bug?

@sbomer
Copy link
Member Author

sbomer commented Apr 17, 2019

I'm personally hoping for an improved error and the custom opt-out not requiring PublicKey and PublicKeyToken to be set. However it's not blocking anything nor am I actively waiting on it. Triage/close as you see fit. :)

sbomer added a commit to sbomer/linker that referenced this issue May 2, 2019
sbomer added a commit to sbomer/linker that referenced this issue May 2, 2019
marek-safar pushed a commit to dotnet/linker that referenced this issue May 3, 2019
* Use SDK-style projects for linker and tests

* Clean up linker project file

Separate out the illink build properties from the monolinker
properties. Also disable building illink for net46 on unix/core
msbuild, which doesn't work due to missing reference assemblies. This
check is more specific than what we used to have, so that illink can
potentially be built with the mono runtime.

Building this project with "nuget restore" and "msbuild" will only
work with the default configuration because nuget restore does not set
the configuration and would see a different target framework from msbuild.

* Fix assembly title and description for illink

* Fix debug and optimization info for illink configurations

* Remove references to old illink solutions

* Update cecil submodule to latest mono/cecil

* Fix typo

* Update cecil configurations in illink.sln

* Fix cecil strongname build failure with arcade

Work around dotnet/arcade#2321

* Remove unused configs from monolinker.sln

Also add a missing release config for cecil

* Set PublicKey and PublicKeyToken in cecil overrides
@markwilkie
Copy link
Member

Adding to the SDK epic (priority) for post P7

@michellemcdaniel michellemcdaniel mentioned this issue Feb 14, 2022
74 tasks
tkapin pushed a commit to tkapin/runtime that referenced this issue Jan 31, 2023
* Use SDK-style projects for linker and tests

* Clean up linker project file

Separate out the illink build properties from the monolinker
properties. Also disable building illink for net46 on unix/core
msbuild, which doesn't work due to missing reference assemblies. This
check is more specific than what we used to have, so that illink can
potentially be built with the mono runtime.

Building this project with "nuget restore" and "msbuild" will only
work with the default configuration because nuget restore does not set
the configuration and would see a different target framework from msbuild.

* Fix assembly title and description for illink

* Fix debug and optimization info for illink configurations

* Remove references to old illink solutions

* Update cecil submodule to latest mono/cecil

* Fix typo

* Update cecil configurations in illink.sln

* Fix cecil strongname build failure with arcade

Work around dotnet/arcade#2321

* Remove unused configs from monolinker.sln

Also add a missing release config for cecil

* Set PublicKey and PublicKeyToken in cecil overrides


Commit migrated from dotnet/linker@6280036
@missymessa missymessa added this to the Arcade SDK milestone Apr 24, 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

4 participants