dotnet / project-system

The .NET Project System for Visual Studio
MIT License
971 stars 389 forks source link

Framework references not populated if called using the DTE #1826

Open jmarolf opened 7 years ago

jmarolf commented 7 years ago
  1. Create a csproj that targets net461 like so:
    <Project Sdk=""Microsoft.NET.Sdk"">
    <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    </PropertyGroup>
    </Project>
  2. Attempt to add an assembly reference using the DTE
    string assemblyName = "WindowsBase";
    var vsproject = ((VSProject)project.Object);
    vsproject.References.Add(assemblyName);

Expected: the WindowsBase reference is resolved and added to the project.

Actual:

System.ArgumentException : Unable to find a type of reference that is appropriate for this file: "WindowsBase".

    Server stack trace:
    at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAVSReferences.Add(String bstrPath)
    at Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess.SolutionExplorer_InProc.AddMetadataReference(String assemblyName, String projectName)
    at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Notes: This scenario works in the Reference Manager because we appear to populate the Framework references asynchronously on demand. image

If the Framework references are populated by the Reference Manager first, subsequent calls to vsproject.References.Add(assemblyName) will succeed in finding the framework reference. It seems we need to add some logic ensure that this code path also causes the Framework references to be populated.

This is blocking integration tests.

davkean commented 7 years ago

If you put a pause of 10 seconds before you attempt to add the reference, does it work?

jmarolf commented 7 years ago

@davkean it does, seems we need to way to wait for all the Framework references to be discovered.

davkean commented 7 years ago

@jmarolf I believe this is because we have async project tree load turned on, this is supposed to turn off so that the behavior is similar the legacy project system, I've filed: https://github.com/dotnet/roslyn-project-system/issues/1827 to track this. I'll leave this open just for verification when I turn async load off.

davkean commented 7 years ago

We looked at this async project load is not the cause.

aodl commented 5 years ago

Until this is fixed is there a recommended work around - an event to listen for that would indicated that vsproject.References has been populated?