I keep forgetting to fix my style cop warnings (mainly the using statements need to be in alphabetical order and trailing whitespace at the end of the line) and @DonovanBrown finally got sick of it and told me to turn our Code Analysis warnings into errors. Simple enough. I flip the switch, fix all my “errors”, check the code in, VSTS kicks off a build and…… Build Failure!
Whaaaat? I look at the build report and I see this:
2017-08-03T15:51:17.8618750Z C:\Program Files\dotnet\sdk\1.0.0-rc4-004771\Microsoft.CSharp.CurrentVersion.targets(133,9): warning MSB3884: Could not find rule set file “\_stylecop\StyleCopRules.ruleset”. [d:\WinBldBox-3_LoECDA_Service1\2\s\src\LoECDA\LoECDA.csproj]
2017-08-03T15:51:19.6744229Z Controllers\AccountController.cs(1,1): error SA1652: Enable XML documentation output [d:\WinBldBox-3_LoECDA_Service1\2\s\src\LoECDA\LoECDA.csproj]
2017-08-03T15:51:19.6744229Z Controllers\AccountController.cs(1,1): error SA1633: The file header is missing or not located at the top of the file. [d:\WinBldBox-3_LoECDA_Service1\2\s\src\LoECDA\LoECDA.csproj]
This doesn’t make any sense. This totally builds just fine on my machine (haha, had to write that)! I get that the these are style cop warnings that are now flagged as errors… But wait, these style cop warnings/errors were those that we already decided as a team to not follow… And that’s when I saw the highlighted warning. Could not find the rule set file. Hmmm… how come Visual Studio totally finds my StyleCopRules.ruleset file but dotnet build does not (I am using the .NET Core task to build and run my unit tests in VSTS)? After some more digging, I realized that in the .csproj, I defined the CodeAnalysisRuleSet to use an absolute path with $(SolutionDir)
I changed this to use a relative path to my .csproj and voila! Everything worked.
If you are writing a .net core app and using VSTS to build your app using the .net core task and you are using Code Analysis Rulesets, make sure you use relative paths to describe where the .ruleset files are in your .csproj!