Skip to content

Support extern alias in generated code. #2289

Open
@teo-tsirpanis

Description

@teo-tsirpanis

I was benchmarking the old and new version of my library and the benchmark methods were returning objects of a type with the same name from the old or new assembly. I can't vary the NuGet package versions because the new version is not yet released and the API is different.

In my benchmark code I used extern alias to point to the old library but this did not carry over to the code BenchmarkDotNet generated, causing error CS0433: The type 'Grammar' exists in both 'Farkle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'FarkleNeo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I found a workaround by returning object so I guess it's a pretty niche scenario.

Activity

timcassell

timcassell commented on Jul 27, 2023

@timcassell
Collaborator

For this to be done automatically, this is blocked by #1403 (unless we want to pass /r arguments to the compiler). We also will need to figure out how to determine when to use extern alias (I suspect we'll have to scan all assemblies for the type to check for duplicated Type.FullName, since we don't have the /r compilation information at runtime).

We could possibly expose an API to support this case manually, but I'd prefer not to.

timcassell

timcassell commented on Mar 7, 2024

@timcassell
Collaborator

@teo-tsirpanis How did you get it to work outside of BDN? When I try, I hit this long-standing issue. dotnet/msbuild#4943

I'm not sure if we can support this in BDN if msbuild doesn't even properly support it.

teo-tsirpanis

teo-tsirpanis commented on Mar 7, 2024

@teo-tsirpanis
ContributorAuthor

In my case the two assemblies have different names (one is called Farkle and the other is called FarkleNeo). I use extern alias in my benchmark, and because I return object from my methods, the auto-generated files don't require to use extern alias.

Madajevas

Madajevas commented on Aug 13, 2024

@Madajevas

Any update or workaround for this?

teo-tsirpanis

teo-tsirpanis commented on Aug 13, 2024

@teo-tsirpanis
ContributorAuthor

You can avoid exposing the extern aliased type in the signature of your benchmark methods. For my case I changed the methods to return object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @AndreyAkinshin@Madajevas@teo-tsirpanis@timcassell

        Issue actions

          Support `extern alias` in generated code. · Issue #2289 · dotnet/BenchmarkDotNet