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

Remove dependency on deprecated ref package #74814

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eng/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
<PackageVersion Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta2-22302-02" />
<PackageVersion Include="Microsoft.Metadata.Visualizer" Version="1.0.0-beta3.21075.2" />
<PackageVersion Include="Microsoft.ILVerification" Version="8.0.0-rtm.23523.3" />
<PackageVersion Include="Microsoft.NET.Build.Extensions" Version="2.2.101" />
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="5.0.0" />
<PackageVersion Include="Microsoft.VisualStudio.Cache" Version="17.3.26-alpha" />
<PackageVersion Include="Microsoft.VisualStudio.Diagnostics.Measurement" Version="17.9.36343-preview.3" />
Expand Down
4 changes: 0 additions & 4 deletions src/Compilers/Test/Core/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ Add-TargetFramework "SystemThreadingTasksExtensions" '$(PkgSystem_Threading_Task
'NetStandard20Lib#\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll'
)
Copy link
Member

Choose a reason for hiding this comment

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

The grim reaper advances another door.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only three doors left.


Add-TargetFramework "BuildExtensions" '$(PkgMicrosoft_NET_Build_Extensions)\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions' @(
'NetStandardToNet461#net461\lib\netstandard.dll'
)

$targetsContent += @"
</ItemGroup>
</Project>
Expand Down
13 changes: 0 additions & 13 deletions src/Compilers/Test/Core/Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,5 @@ public static class SystemThreadingTasksExtensions
public static PortableExecutableReference PortableLib { get; } = AssemblyMetadata.CreateFromImage(ResourcesSystemThreadingTasksExtensions.PortableLib).GetReference(display: "System.Threading.Tasks.Extensions.dll (systemthreadingtasksextensions)", filePath: "PortableLib.dll");
public static PortableExecutableReference NetStandard20Lib { get; } = AssemblyMetadata.CreateFromImage(ResourcesSystemThreadingTasksExtensions.NetStandard20Lib).GetReference(display: "System.Threading.Tasks.Extensions.dll (systemthreadingtasksextensions)", filePath: "NetStandard20Lib.dll");
}
public static class ResourcesBuildExtensions
{
private static byte[] _NetStandardToNet461;
public static byte[] NetStandardToNet461 => ResourceLoader.GetOrCreateResource(ref _NetStandardToNet461, "netstandardtonet461.buildextensions.netstandard.dll");
public static ReferenceInfo[] All => new[]
{
new ReferenceInfo("NetStandardToNet461.dll", NetStandardToNet461),
};
}
public static class BuildExtensions
{
public static PortableExecutableReference NetStandardToNet461 { get; } = AssemblyMetadata.CreateFromImage(ResourcesBuildExtensions.NetStandardToNet461).GetReference(display: "netstandard.dll (buildextensions)", filePath: "NetStandardToNet461.dll");
}
}
}
4 changes: 0 additions & 4 deletions src/Compilers/Test/Core/Generated.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@
<LogicalName>netstandard20lib.systemthreadingtasksextensions.System.Threading.Tasks.Extensions.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\systemthreadingtasksextensions\System.Threading.Tasks.Extensions.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NET_Build_Extensions)\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\netstandard.dll">
<LogicalName>netstandardtonet461.buildextensions.netstandard.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\buildextensions\netstandard.dll</Link>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@

<!-- Needed to find the Unsafe.dll binary to lay out at runtime for the compiler when testing analyzers. -->
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
<PackageReference Include="Microsoft.NET.Build.Extensions" IncludeAssets="none" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="System.Threading.Tasks.Extensions" IncludeAssets="none" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.CSharp" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.VisualBasic" IncludeAssets="none" PrivateAssets="all" GeneratePathProperty="true" />
Expand Down
6 changes: 0 additions & 6 deletions src/Compilers/Test/Core/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,6 @@ public virtual void Dispose()

public static MetadataReference NetStandard20Ref => s_std20Ref.Value;

private static readonly Lazy<MetadataReference> s_46NetStandardFacade = new Lazy<MetadataReference>(
() => AssemblyMetadata.CreateFromImage(ResourcesBuildExtensions.NetStandardToNet461).GetReference(display: "netstandard20.netstandard.dll"),
LazyThreadSafetyMode.PublicationOnly);

public static MetadataReference Net46StandardFacade => s_46NetStandardFacade.Value;

private static readonly Lazy<MetadataReference> s_systemRef = new Lazy<MetadataReference>(
() => AssemblyMetadata.CreateFromImage(Net461.Resources.System).GetReference(display: "System.v4_0_30319.dll"),
LazyThreadSafetyMode.PublicationOnly);
Expand Down
32 changes: 23 additions & 9 deletions src/Workspaces/CoreTest/FindReferencesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand All @@ -23,6 +24,22 @@ public class FindReferencesTests : TestBase
private static Workspace CreateWorkspace(Type[] additionalParts = null)
=> new AdhocWorkspace(FeaturesTestCompositions.Features.AddParts(additionalParts).GetHostServices());

private static Solution AddProjectWithMetadataReferences(Solution solution, string projectName, string languageName, string code, IEnumerable<MetadataReference> metadataReference, params ProjectId[] projectReferences)
{
var suffix = languageName == LanguageNames.CSharp ? "cs" : "vb";
var pid = ProjectId.CreateNewId();
var did = DocumentId.CreateNewId(pid);
var pi = ProjectInfo.Create(
pid,
VersionStamp.Default,
projectName,
projectName,
languageName,
metadataReferences: metadataReference,
projectReferences: projectReferences.Select(p => new ProjectReference(p)));
return solution.AddProject(pi).AddDocument(did, $"{projectName}.{suffix}", SourceText.From(code));
}

private static Solution AddProjectWithMetadataReferences(Solution solution, string projectName, string languageName, string code, MetadataReference metadataReference, params ProjectId[] projectReferences)
{
var suffix = languageName == LanguageNames.CSharp ? "cs" : "vb";
Expand Down Expand Up @@ -352,9 +369,9 @@ public interface I
{
System.Uri Get();
}
}", NetStandard20Ref);
}", NetStandard20.References.All);

solution = AddProjectWithMetadataReferences(solution, "DesktopProject", LanguageNames.CSharp, @"
solution = AddProjectWithMetadataReferences(solution, "NetCoreProject", LanguageNames.CSharp, @"
Copy link
Member Author

Choose a reason for hiding this comment

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

This changes the test here from being a net461 project referencing a netstandard2.0 to net8.0 referencing netstandard2.0. That actually matches the original issue closer by my reading. It is still under the hood though verifying that we can map symbols between the two projects when the underlying references substantially change and we have to deal with mapped symbols.

Waiting for @sharwell, @jasonmalinowski or @CyrusNajmabadi to sign off on this or let me know if I missed a subtle issue about this test.

Copy link
Member

Choose a reason for hiding this comment

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

We probably went with testing netstandard and .NET Framework since they'd be most "different" in terms of types being in different assemblies. Is there a reason we can't keep this a .NET Framework ref?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a reason we can't keep this a .NET Framework ref?

It's difficult to keep the net461 reference because of how the mapping between netstandard2.0 to net461 works under the hood. It effectively downloads / loads a deprecated NuPkg that adds a couple dozen facade assemblies to the build. This is needed because netstandard2.0 was somewhat ret-conned into net461. If there were a lot of tests that did the netstandard -> net461 mapping I'd be inclined to get that all mapped out with basic ref assemblies and use it. But this the only test that does this.

We probably went with testing netstandard and .NET Framework since they'd be most "different" in terms of types being in different assemblies

I assure you they are quite different in netstandard2.0 and any modern .NET core TFM. For example any core primitive type goes from being defined in netstandard.dll to System.Runtime.dll. They are, quite unfortunately, substantially different.

Copy link
Member

Choose a reason for hiding this comment

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

or example any core primitive type goes from being defined in netstandard.dll to System.Runtime.dll

OK that would worry me less here; as long as we have some test that is asserting that we can handle the cases where System.Object comes from different assemblies, we're probably good.

using N;

namespace N2
Expand All @@ -366,12 +383,9 @@ public System.Uri Get()
return null;
}
}
}", SystemRef_v46, solution.Projects.Single(pid => pid.Name == "NetStandardProject").Id);

var desktopProject = solution.Projects.First(p => p.Name == "DesktopProject");
solution = solution.AddMetadataReferences(desktopProject.Id, [MscorlibRef_v46, Net46StandardFacade]);
}", NetCoreApp.References, solution.Projects.Single(pid => pid.Name == "NetStandardProject").Id);

desktopProject = solution.GetProject(desktopProject.Id);
var netCoreProject = solution.Projects.First(p => p.Name == "NetCoreProject");
var netStandardProject = solution.Projects.First(p => p.Name == "NetStandardProject");

var interfaceMethod = (IMethodSymbol)(await netStandardProject.GetCompilationAsync()).GetTypeByMetadataName("N.I").GetMembers("Get").First();
Expand All @@ -383,7 +397,7 @@ public System.Uri Get()
foreach (var r in references)
projectIds.Add(solution.GetOriginatingProjectId(r.Definition));

Assert.True(projectIds.Contains(desktopProject.Id));
Assert.True(projectIds.Contains(netCoreProject.Id));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35786")]
Expand Down Expand Up @@ -416,7 +430,7 @@ interface ITestBase

using var workspace = CreateWorkspace();
var solution = GetMultipleDocumentSolution(workspace, [implText, interface1Text, interface2Text]);
solution = solution.AddMetadataReferences(solution.ProjectIds.Single(), [MscorlibRef_v46, Net46StandardFacade, SystemRef_v46, NetStandard20Ref]);
solution = solution.AddMetadataReferences(solution.ProjectIds.Single(), NetFramework.References);

var project = solution.Projects.Single();
var compilation = await project.GetCompilationAsync();
Expand Down
Loading