Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have an analyzer on a .net 4.5 project?

I have an OSS project on GitHub being built against .NET 4.5 on AppVeyor CI with Visual Studio 2017 (not the preview stuff, just 2017).

The solution builds a COM add-in that extends a famously dreaded legacy Win32 IDE, and we've established that the earliest Windows version we need to run on, is Vista (so, .net 4.5 and its async/await awesomeness).

So far, so good. Now building a COM-visible .net DLL is one thing, and building a COM add-in that runs in-process, hosted in a fussy application that was last updated 20 years ago, is another: we can't rely on .net garbage collection cleaning up RCW's nondeterministically, so it's fairly easy to accidentally leak a COM object and introduce serious runtime (teardown actually) issues, so one of the core contributors is adding a Roslyn analyzer project to the solution that's going to help contributors old & new with that, by preventing a build that would introduce such a leak.

So all .csproj files in the solution are getting this diff:

+  <ItemGroup>
+    <Analyzer Include="..\RubberduckCodeAnalysis\RubberduckCodeAnalysis\bin\Release\netstandard1.3\RubberduckCodeAnalysis.dll" />
+  </ItemGroup>

The analyzer project is thus required to build first.

There's the .sln diff showing the GUIDs for the new analyzer project:

+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RubberduckCodeAnalysis", "RubberduckCodeAnalysis\RubberduckCodeAnalysis\RubberduckCodeAnalysis.csproj", "{A2B4E037-A446-41B9-A304-F91C7C7A6972}"
+EndProject

And then the .sln diff showing one of the solution's projects and how the analyzer has been added as a dependency in order to control the build order:

 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.Parsing", "Rubberduck.Parsing\Rubberduck.Parsing.csproj", "{A4A618E1-CBCA-435F-9C6C-5181E030ADFC}"
    ProjectSection(ProjectDependencies) = postProject
+       {A2B4E037-A446-41B9-A304-F91C7C7A6972} = {A2B4E037-A446-41B9-A304-F91C7C7A6972}
        {8CE35EB3-8852-4BA1-84DD-DF3F5D2967B0} = {8CE35EB3-8852-4BA1-84DD-DF3F5D2967B0}
    EndProjectSection
 EndProject

Which brings me to the AppVeyor build error I'm stuck at:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1603,5): error : Project 'C:\projects\rubberduck\RubberduckCodeAnalysis\RubberduckCodeAnalysis\RubberduckCodeAnalysis.csproj' targets 'netstandard1.3'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.5'. [C:\projects\rubberduck\Rubberduck.Parsing\Rubberduck.Parsing.csproj]

On a local debug build, the analyzer project can be built manually, and then the rest of the solution can be built & analyzed just fine, without needing to hack up project dependencies.

On the AppVeyor CI build server though, the analyzer project is just a DLL that's part of the solution, and if we don't tell it to be built first, then the analyzer DLL won't be found and the solution won't build.

Looks like I'm stuck, whichever side I look at the problem. My users are all Win32 users, I don't care for portability; I do care to run on Windows Vista though, so is there a way I can get this to build on CI without retargeting the projects to .NET Standard 1.3?

like image 344
Mathieu Guindon Avatar asked May 01 '18 16:05

Mathieu Guindon


1 Answers

If you look at the documentation of .NET Standard, you will see that version 1.3 is compatible with .NET Framework 4.6:

enter image description here

You say that you need to support Windows Vista, and you are lucky, because the last version of .NET supported in Windows Vista (SP2 required) is .NET Framework 4.6: .NET Framework system requirements.

So, I would suggest you to update all your projects to .NET Framework 4.6 and you should not see any more compatibility problems.

like image 57
Camilo Terevinto Avatar answered Sep 29 '22 21:09

Camilo Terevinto