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

EnableNETAnalyzers feature not working #12784

Closed
carlossanlop opened this issue Aug 5, 2020 · 5 comments · Fixed by #12816
Closed

EnableNETAnalyzers feature not working #12784

carlossanlop opened this issue Aug 5, 2020 · 5 comments · Fixed by #12816

Comments

@carlossanlop
Copy link
Member

This file has bugs in these lines:

In these two locations, there is an extra space in $(EnableNETAnalyzers ) before the closing parenthesis, causing MSBuild to not find that property:

<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers )' == '' And

<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers )' == ''">false</EnableNETAnalyzers>

So even if I set EnableNETAnalyzers to true in my csproj, it gets overriden to false because this line overrides it:

<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers )' == ''">false</EnableNETAnalyzers>

Once that spaces get removed, the DLLs are not found because their paths are relative to the project, not to the SDK:

Include="..\analyzers\Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll"

Include="..\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll"

Include="..\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll"

Error:

CSC : error CS0006: Metadata file '..\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll' could not be found [D:\testing\ConsoleCore\ConsoleCore.csproj]
CSC : error CS0006: Metadata file '..\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll' could not be found [D:\testing\ConsoleCore\ConsoleCore.csproj]

So the fix is to prefix the 3 DLL paths with $(MSBuildThisFileDirectory) like this:

Include="$(MSBuildThisFileDirectory)..\analyzers\Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll"

Once fixed, it can find instances of the new Roslyn analyzers.

This bug is present in master and in Preview8.

cc @jmarolf @mavasani

@jmarolf
Copy link
Contributor

jmarolf commented Aug 5, 2020

fixed with #12785

@jmarolf jmarolf closed this as completed Aug 5, 2020
@carlossanlop
Copy link
Member Author

@jmarolf this needs to be fixed in master as well.

@carlossanlop carlossanlop reopened this Aug 6, 2020
jmarolf pushed a commit to jmarolf/sdk-1 that referenced this issue Aug 6, 2020
@mavasani
Copy link
Member

mavasani commented Aug 7, 2020

@jmarolf Seems like the above PRs updated the targets file but missed updating the props file to prepend $(MSBuildThisFileDirectory) to file names:

<Import Project="..\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.props"

I'll re-open this issue to track that work.

@mavasani mavasani reopened this Aug 7, 2020
@jmarolf
Copy link
Contributor

jmarolf commented Aug 7, 2020

hmm, trying this out locally I cannot reproduce the issue. Using this installer I ran dotnet new console && dotnet build -pp:imports.xml.

This gives me a imports.xml file that shows all the props and targets contents used in the project and I can see the correct props being imported.

...
  <!--
============================================================================================================================================
  <Import Project="..\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.props" Condition="'$(MSBuildProjectExtension)' == '.csproj' Or '$(MSBuildProjectExtension)' == '.vbproj'">

C:\Program Files\dotnet\sdk\5.0.100-rc.1.20407.4\Sdks\Microsoft.NET.Sdk\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.props
============================================================================================================================================
-->
  <!-- 
    This property group prevents the rule ids implemented in this package to be bumped to errors when
    the 'CodeAnalysisTreatWarningsAsErrors' = 'false'.
  -->
  <PropertyGroup Condition="'$(CodeAnalysisTreatWarningsAsErrors)' == 'false'" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <WarningsNotAsErrors>$(WarningsNotAsErrors);CA1000;CA1001;CA1002;CA1003;CA1005;CA1008;CA1010;CA1012;CA1014;CA1016;CA1017;CA1018;CA1019;CA1021;CA1024;CA1027;CA1028;CA1030;CA1031;CA1032;CA1033;CA1034;CA1036;CA1040;CA1041;CA1043;CA1044;CA1045;CA1046;CA1047;CA1050;CA1051;CA1052;CA1054;CA1055;CA1056;CA1058;CA1060;CA1061;CA1062;CA1063;CA1064;CA1065;CA1066;CA1067;CA1068;CA1069;CA1070;CA1200;CA1303;CA1304;CA1305;CA1307;CA1308;CA1309;CA1401;CA1417;CA1501;CA1502;CA1505;CA1506;CA1507;CA1508;CA1509;CA1700;CA1707;CA1708;CA1710;CA1711;CA1712;CA1713;CA1715;CA1716;CA1720;CA1721;CA1724;CA1725;CA1801;CA1802;CA1805;CA1806;CA1810;CA1812;CA1813;CA1814;CA1815;CA1816;CA1819;CA1820;CA1821;CA1822;CA1823;CA1824;CA1825;CA1826;CA1827;CA1828;CA1829;CA1830;CA1831;CA1832;CA1833;CA1834;CA1835;CA1836;CA1837;CA1838;CA2000;CA2002;CA2007;CA2008;CA2009;CA2011;CA2012;CA2013;CA2014;CA2015;CA2016;CA2100;CA2101;CA2109;CA2119;CA2153;CA2200;CA2201;CA2207;CA2208;CA2211;CA2213;CA2214;CA2215;CA2216;CA2217;CA2218;CA2219;CA2224;CA2225;CA2226;CA2227;CA2229;CA2231;CA2234;CA2235;CA2237;CA2241;CA2242;CA2243;CA2244;CA2245;CA2246;CA2247;CA2248;CA2249;CA2300;CA2301;CA2302;CA2305;CA2310;CA2311;CA2312;CA2315;CA2321;CA2322;CA2326;CA2327;CA2328;CA2329;CA2330;CA2350;CA2351;CA2352;CA2353;CA2354;CA2355;CA2356;CA2361;CA2362;CA3001;CA3002;CA3003;CA3004;CA3005;CA3006;CA3007;CA3008;CA3009;CA3010;CA3011;CA3012;CA3061;CA3075;CA3076;CA3077;CA3147;CA5350;CA5351;CA5358;CA5359;CA5360;CA5361;CA5362;CA5363;CA5364;CA5365;CA5366;CA5367;CA5368;CA5369;CA5370;CA5371;CA5372;CA5373;CA5374;CA5375;CA5376;CA5377;CA5378;CA5379;CA5380;CA5381;CA5382;CA5383;CA5384;CA5385;CA5386;CA5387;CA5388;CA5389;CA5390;CA5391;CA5392;CA5393;CA5394;CA5395;CA5396;CA5397;CA5398;CA5399;CA5400;CA5401;CA5402;CA5403;IL3000;IL3001</WarningsNotAsErrors>
  </PropertyGroup>
  <!--
...

So I do not think the imports need to have the qualifier in the path. I will use this to track writing a unit test to make sure this does not regress. @mavasani I assume if these props files are not imported we would expect the build to fail with <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors> specified with <TreatWarningsAsErrors>true</TreatWarningsAsErrors>?

@mavasani
Copy link
Member

mavasani commented Aug 7, 2020

Sounds good - I just noticed missing $(MSBuildThisFileDirectory) in props file while testing out some changes. I have no failing repro case to show it as being required. Your testing should suffice to indicate it is not. Feel free to close out the issue.

@jmarolf jmarolf closed this as completed Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants