Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

kzu
Copy link
Contributor

@kzu kzu commented Jul 19, 2019

Given that InternalsVisibleTo (IVT) is such a common assembly-level attribute, this adds support
for specifying it directly via simple items, such as:

  <ItemGroup>
    <InternalsVisibleTo Include="MyLibrary.Tests" />
  </ItemGroup>

Optionally, a Key metadata can be specified to provide a strong-named IVT:

  <ItemGroup>
    <InternalsVisibleTo Include="MyLibrary.Tests" Key="PUBLIC_KEY" />
  </ItemGroup>

The targets will also use automatically a $(PublicKey) if available and no %(Key) metadata
override is found. Otherwise, it will default to an IVT without a key.

This also avoids having to learn the _Parameter1 syntax in AssemblyAttribute elements, and is
more similar to the way other higher-level properties like AssemblyTitle or Product are also
turned into assembly attributes.

To turn off this feature, set $(GenerateInternalsVisibleToAttributes) to false.

Partially fixes #3166

@peterhuene peterhuene added this to the 3.0.1xx milestone Jul 19, 2019
@peterhuene peterhuene requested a review from a team July 19, 2019 17:47
@peterhuene
Copy link
Contributor

Hi @kzu. This looks good.

Could you add some test coverage to this PR?

@nguerrera
Copy link
Contributor

This is going to conflict with the unofficial feature in Arcade so would need to be coordinated.

https://github.com/dotnet/arcade/blob/671bfe2954fe2e0fc2052cb0ee59cbfe9e5e8801/src/Microsoft.DotNet.Arcade.Sdk/tools/GenerateInternalsVisibleTo.targets

That one supports using $(PublicKey) or %(Key) metadata AFAICT. I think we'll want this to be a superset of that in functionality, ideally. Or we have to be able to turn this one off to enable that one.

cc @tmat

@tmat
Copy link
Member

tmat commented Jul 19, 2019

We shouldn't end up with two ways of doing it. Let's have one impl that supports all we need.

@kzu
Copy link
Contributor Author

kzu commented Jul 25, 2019

Good point @nguerrera and @tmat. Added support for the existing arcade stuff too, which should make it a drop-in replacement. It can also be turned off now.

@kzu
Copy link
Contributor Author

kzu commented Jul 25, 2019

@peterhuene just like for the other PR, if you can point me to existing tests for AssemblyAttribute generation, I can add to that. Thanks!

@sharwell
Copy link
Contributor

@nguerrera Where would a new feature like this get documented, such that once it's available we can point users to it?

@rainersigwald
Copy link
Member

@peterhuene
Copy link
Contributor

@kzu here is a test that is setting the individual properties that cause additional AssemblyAttribute items to be defined.

We should probably add a test to this file to cover setting InternalsVisibleTo items in the test project file and reflecting on the output assembly to ensure the attributes were set.

@kzu
Copy link
Contributor Author

kzu commented Jul 29, 2019

AssemblyAttribute is already missing from docs :(

@kzu
Copy link
Contributor Author

kzu commented Sep 15, 2019

@peterhuene finally got to implement the unit tests, they cover (I think) all the cases supported by the targets.

…ttributes

Given that `InternalsVisibleTo` (IVT) is such a common assembly-level attribute, this adds support
for specifying it directly via simple items, such as:

```
  <ItemGroup>
    <InternalsVisibleTo Include="MyLibrary.Tests" />
  </ItemGroup>
```

Optionally, a `Key` metadata can be specified to provide a strong-named IVT:

```
  <ItemGroup>
    <InternalsVisibleTo Include="MyLibrary.Tests" Key="PUBLIC_KEY" />
  </ItemGroup>
```

The targets will also use automatically a `$(PublicKey)` if available and no `%(Key)` metadata
override is found. Otherwise, it will default to an IVT without a key.

This also avoids having to learn the `_Parameter1` syntax in `AssemblyAttribute` elements, and is
more similar to the way other higher-level properties like `AssemblyTitle` or `Product` are also
turned into assembly attributes.

To turn off this feature, set `$(GenerateInternalsVisibleToAttributes)` to `false`.

Partially fixes dotnet#3166
kzu added a commit to kzu/visualstudio-docs that referenced this pull request Sep 15, 2019
@kzu
Copy link
Contributor Author

kzu commented Sep 15, 2019

Added docs PR too :)

@kzu
Copy link
Contributor Author

kzu commented Sep 16, 2019

Was that fail a fluke?

@nguerrera nguerrera modified the milestones: 3.0.1xx, 5.0.1xx Oct 28, 2019
@kzu
Copy link
Contributor Author

kzu commented Jan 14, 2020

Is there something I can do to get this PR green?

@dsplaisted
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dsplaisted
Copy link
Member

Is there something I can do to get this PR green?

One leg was failing but the results were no longer available, so I've restarted CI

Copy link
Member

@sfoslund sfoslund left a comment

Choose a reason for hiding this comment

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

This is green now and it looks good to me. @dsplaisted is this ready to go?

new XAttribute("Include", "Tests"))));
});

new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass();
Copy link
Member

Choose a reason for hiding this comment

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

nit: Same as #3440, restore is no longer necessary

@ggirard07
Copy link

@DanVicarel as this seems to be associated with milestone 5.0.1, I won't expect it prior next .Net Core major release (which is currently planed to be re-branded to .Net 5), then next Visual Studio update to integrate it...

@renatfx
Copy link

renatfx commented Jan 22, 2020

@kzu probably it's already late to ask/comment, but I would like to

Why did you name item metadata Key and not PublicKey?
Finally it goes to IVT contructor as assembly name PublicKey which it is

Why did you introduce PublicKey property?
With the ItemDefinitionGroup feature of MSBuild we can also set the default public key but, what I personally prefer, limiting it to certain items only (comparing to property):

<ItemDefinitionGroup>
  <InternalsVisibleTo>
    <PublicKey>...</PublicKey>
  </InternalsVisibleTo>
</ItemDefinitionGroup>

@kzu
Copy link
Contributor Author

kzu commented Jan 23, 2020

@renatfx it's never late to ask good questions :). The item metadata was named Key for compatibility with the Arcade SDK specifically. Likewise for the $(PublicKey) property.

Finally, doing this in an item definition group is something customers can do themselves. Granted, the SDK could provide that item definition group conditionally, like:

<ItemDefinitionGroup Condition="'$(PublicKey)' != ''">
  <InternalsVisibleTo>
    <PublicKey>$(PublicKey)</PublicKey>
  </InternalsVisibleTo>
</ItemDefinitionGroup>

But it's not entirely clear that every time the current project is strong named, its IVT will point to
other projects with the same key. They might have a different one, and now you'd end up with
a default behavior to turn off...

@renatfx
Copy link

renatfx commented Jan 26, 2020

Well, for me as a .NET (SDK) consumer rather than developer, this is asbolutely unclear:

Why should public .NET SDK be compatible wth internal Arcade SDK?

btw, I didn't realize that $(PublicKey) property has public key of the current project as its value... now I see that using it as an assembly name public key in IVT .ctor by default, only when the current assembly is signed itself, defenitely makes sense.

However, I still would vote (if I could) for PublicKey rather than Key metadata item name.

@tmat
Copy link
Member

tmat commented Jan 26, 2020

Why should public .NET SDK be compatible wth internal Arcade SDK?

It does not. We can rename the Key metadata to PublicKey if it fits better. I filed dotnet/arcade#4658 to follow up in Arcade to use the new official feature, where we can also rename it to whatever name the .NET SDK decides to use.

@renatfx
Copy link

renatfx commented Jan 27, 2020

@tmat ok, great!

dsplaisted pushed a commit to dsplaisted/sdk that referenced this pull request Feb 19, 2020
….2 (dotnet#3439)

- Microsoft.DotNet.Cli.Runtime - 3.1.100-preview3.19552.2
akunzai added a commit to akunzai/GSS.Authorization.OAuth that referenced this pull request Jul 13, 2023
@shueybubbles
Copy link

I see in the binlog that the right public key is being passed in the target, but the emitted assemblyinfo.cs is missing the key. I have VS 17.10.4 and .Net 8 304 SDK. What might cause the target to emit the attribute without the key?
image

kzu added a commit to kzu/spectre.console that referenced this pull request Sep 5, 2024
If the $(PublicKey) property is used, the SDK targets will automatically use it for the assembly attributes.

See dotnet/sdk#3439

Simplifies spectreconsole#1623
patriksvensson pushed a commit to spectreconsole/spectre.console that referenced this pull request Sep 6, 2024
If the $(PublicKey) property is used, the SDK targets will automatically use it for the assembly attributes.

See dotnet/sdk#3439

Simplifies #1623
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.

GenerateAssemblyInfo support for InternalsVisibleToAttribute and AssemblyMetadataAttribute
Morty Proxy This is a proxified and sanitized view of the page, visit original site.