dotnet / dotnet/project-system
Framework references not populated if called using the DTE
- Dominant language
- C#
- Stars
- 1k
- Forks
- 415
- PR merge metrics
- No merged PRs in 30d
Description
1. Create a csproj that targets `net461` like so:
```
net461
```
2. Attempt to add an assembly reference using the DTE
```C#
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.

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.
Contributor guide
Assessment
This issue has not been assessed yet.