msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Intellisense missing on project references (design-time build) if you have a COM reference

Open AndyGerlicher opened this issue 9 years ago • 15 comments

An internal team reported an issue where referenced types were red underlined in Visual Studio but the build (command-line or VS) reported no errors. All projects in the sln were new SDK projects (most multi targeting).

image

AndyGerlicher avatar Oct 05 '17 15:10 AndyGerlicher

I haven't figured out the root cause yet (why this appears to work in VS15.2 but not 15.3), but it looks like this particular issue was caused by the presence of a COMReference. When removing the COMReference dependency all the references immediately appeared and the Error List window emptied (other than a few missing COM reference types of course).

To debug the issue outside of VS I had to emulate a design-time build. I ended up using the file below with SolutionToBuild the .sln file and ProjectToBuild the project in the sln with the issue.

<Project>
  <PropertyGroup>
    <SolutionToBuild>D:\test\...\solution.sln</SolutionToBuild>
    <ProjectToBuild>D:\test\...\project.csproj</ProjectToBuild>
  </PropertyGroup>

  <Target Name="Build" >
    <MSBuild Projects="$(ProjectToBuild)"
             Properties="SolutionFileName=$([System.IO.Path]::GetFileName('$(SolutionToBuild)'));
                 LangName=en-US;
                 Configuration=Debug;
                 LangID=1033;
                 DesignTimeBuild=true;
                 SolutionDir=$([System.IO.Path]::GetDirectoryName('$(SolutionToBuild)'));
                 SolutionExt=.sln;
                 BuildingInsideVisualStudio=true;
                 DefineExplicitDefaults=true;
                 Platform=AnyCPU;
                 SolutionPath=$(SolutionToBuild);
                 SolutionName=$([System.IO.Path]::GetFileNameWithoutExtension('$(SolutionToBuild)'));
                 DevEnvDir=$(DevEnvDir);
                 BuildingProject=false"
             Targets="CollectResolvedSDKReferencesDesignTime;
                DebugSymbolsProjectOutputGroup;
                ResolveComReferencesDesignTime;
                ContentFilesProjectOutputGroup;
                DocumentationProjectOutputGroupDependencies;
                SGenFilesOutputGroup;
                ResolveProjectReferencesDesignTime;
                SourceFilesProjectOutputGroup;
                DebugSymbolsProjectOutputGroupDependencies;
                SatelliteDllsProjectOutputGroup;
                BuiltProjectOutputGroup;
                SGenFilesOutputGroupDependencies;
                ResolveAssemblyReferencesDesignTime;
                CollectSDKReferencesDesignTime;
                DocumentationProjectOutputGroup;
                PriFilesOutputGroup;
                BuiltProjectOutputGroupDependencies;
                SatelliteDllsProjectOutputGroupDependencies" />
  </Target>
</Project>

The issue ended up being that when ResolveComReference was running, it depended on ResolveAssemblyReferences which caused ResolveAssemblyReferences to run too early and then skipped later on in the design-time build. Removing the COMReference from the project caused ResolveComReference to be skipped and the target order was correct. The underlying issue was that for ResolveAssemblyReferences was missing all information about project references. A simple workaround (and may end up being the actual fix) is to add ResolveProjectReferences; to the ResolveAssemblyReferencesDependsOn property: https://github.com/Microsoft/msbuild/blob/5df95761c73cd6b1b2c35a827ed168e32546388e/src/Tasks/Microsoft.Common.CurrentVersion.targets#L1941-L1947

That file is located in a path like C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets. If you modify the file you'll need admin writes and the file might get overwritten by setup the next time there's an upgrade. And be sure to backup the file first.

AndyGerlicher avatar Oct 05 '17 16:10 AndyGerlicher

I can confirm that the proposed solution fixes the issue on our end. Up til now this affected several of our developers.

dpsenner avatar Dec 21 '17 15:12 dpsenner

I can also confirm that adding ResolveProjectReferences fixes this for me as well and my com projects.

ZedIsDead avatar Feb 13 '18 19:02 ZedIsDead

A simpler workaround is to add the following to your project file:


  <Target Name="COMReferencesWorkaround" BeforeTargets="ResolveAssemblyReferences" DependsOnTargets="ResolveProjectReferences">
  </Target>

davkean avatar Feb 14 '18 02:02 davkean

https://github.com/Microsoft/msbuild/issues/2853 is either a dupe of or related to this issue. @AndyGerlicher could you please confirm if the current fix also resolve it? Thanks!

huizhonglong avatar Feb 14 '18 16:02 huizhonglong

@davkean Your simpler work around solved this issue. Also, I checked my Microsoft.Common.CurrentVersion.targets file and it did already have the ResolveAssemblyReferencesDependsOn in there yet I was still having the issue. Thanks!

ryanbehr avatar Mar 15 '18 21:03 ryanbehr

Trying the workaround gets rid this error and generates new ones. Now I get intellisense errors such as:

"The type task is defined in an assembly that is not references. You must add a reference to assembly 'netstandard...'"

Anyone else experiencing this?

ptsoccer avatar Apr 12 '18 22:04 ptsoccer

I can confirm that we've also hit this issue. For reference, our setup is:

- Class library --> ADODB ref
- Unit test --> ADODB ref & Class Library ref

The class library builds just fine, but the unit test project intellisense fails when the ADODB COM reference is present.

Purely for background colour, the reason we need a COM reference is that we're porting an old C++ COM-registered DLL to .NET to fix an issue whereby we still rely on TLS 1.0, and we were hoping to use modern tooling whilst still targeting the full Fx.

keith-vikode avatar May 31 '18 08:05 keith-vikode

At some point between visual studio version 15.7.5 and 15.8.1 this became an issue again. My solution has a few com references and after updating from 15.7.5 to 15.8.1, suddenly I have thousands of intellisense errors even though the project builds and runs just fine.

@Davkean workaround described above on Feb 13, 2018 (editing the project file for every project in the solution) does resolve the problem for me.

However, I'm wondering if this workaround is the 'official' solution, or if this indicates that the bug should be re-opened and fixed again?

lbs-mike avatar Aug 20 '18 12:08 lbs-mike

@AndyGerlicher What release did this change make it into?

davkean avatar Aug 20 '18 22:08 davkean

For sure 15.8, not sure about 15.7 without checking further. But it shouldn't have changed since then. You should be able to remove the workaround now if you're on latest public release (15.8).

AndyGerlicher avatar Aug 20 '18 22:08 AndyGerlicher

I could be wrong, I don't know anything about msbuild. Perhaps something else is/was causing the issue.

I was on version 15.7.5 (maybe 15.7.6?) with no problems of any kind. Updated to 15.8.1 and suddenly red squiggles in every file of every project in the solution. Did clean/rebuild, deleted .suo files, restarted PC multiple times. Nothing fixed it except the workaround mentioned previously.

lbs-mike avatar Aug 21 '18 11:08 lbs-mike

Although, to expand a little bit, I didn't have red squiggles on the references at the top of each file. I had green squiggles on those references, and only the references which pointed to dependent projects in the solution.

But in each file, any identifier that referenced a type that was defined in a dependent project had a red squiggle underneath. So 10,000s of red squiggles.

Is this unrelated to this particular bug? Perhaps this should be moved somewhere else?

lbs-mike avatar Aug 21 '18 11:08 lbs-mike

I have the same issues after VS update to 15.8 and 15.8.1

@davkean For me it was also the release 15.8. It all worked fine with 15.7 @lbs-mike Did you found a solution for the problem?

raphibolliger avatar Aug 23 '18 06:08 raphibolliger

@raphibolliger Yes, refer to the ComReferencesWorkaround described in @davkean's post further up in this thread (dated Feb 13, 2018). This worked for me. https://github.com/Microsoft/msbuild/issues/2591#issuecomment-365478327

lbs-mike avatar Aug 23 '18 11:08 lbs-mike