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

Have a built-in way to add Assembly to analyzer/generator testing #1111

Open
Youssef1313 opened this issue Jul 29, 2023 · 2 comments
Open

Have a built-in way to add Assembly to analyzer/generator testing #1111

Youssef1313 opened this issue Jul 29, 2023 · 2 comments
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing

Comments

@Youssef1313
Copy link
Member

Currently, there is ReferenceAssemblies which provides base reference assemblies for various TFMs, with the ability to add NuGet packages. This is often good enough, but in some cases we want to add a reference to an assembly built by the solution.

I found that aspnetcore needed this as well, and wrote this: https://github.com/dotnet/aspnetcore/blob/f107566c2ef1c9dd648b04509249838d656ac72b/src/Shared/AnalyzerTesting/TestReferences.cs#L18

I wonder if this could be part of the testing library?

@sharwell
Copy link
Member

sharwell commented Aug 2, 2023

The behavior in aspnetcore doesn't match the behavior of NuGet/MSBuild for compile time, so I wouldn't want to add that in its current state. The intent of ReferenceAssemblies (and any other similar feature added directly to the SDK) would be to match the true build. As such, my expectation for implementation would be for the feature to always produce a collection of MetadataReference instances which is the same set of references one would get if they referenced the output of the project in question. It should not include any assemblies that the project brought in through NuGet packages, since these would also be brought in through the packages functionality of ReferenceAssemblies.

@dansiegel
Copy link

I might suggest here that we use MSBuild to help generate what we need. Perhaps we could have something like:

<ItemGroup>
  <MetaProjectReference Include="../MyProject/MyProject.csproj" />
</ItemGroup>

The thought here is that this can act similar to a ProjectReference in that it will ensure that the referenced project is built before the current project, however without actually adding any references to the output assemblies. The key would however be to Generate a class as part of the build that would let developers get the required references like:

var references = MetaProjectReference.MyProject.Net80;

The goal there should be that all of the resolved references for that project are included and that it can be done for any TargetFrameworks that may be included as part of MyProject

@sharwell sharwell added the Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing
Projects
None yet
Development

No branches or pull requests

3 participants