0

I have a solution with about 80 projects in it. Each project has StyleCop MSBuild integration enabled:

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(ProgramFiles)\MSBuild\Microsoft\StyleCop\v4.4\Microsoft.StyleCop.targets" />

I need to remove this from ALL projects. is there any way short of checking out and hand-editing each and every .csproj file?

zaitsman
  • 8,984
  • 6
  • 47
  • 79
  • 1
    possible duplicate of [How to get rid of StyleCop](http://stackoverflow.com/questions/4399061/how-to-get-rid-of-stylecop) – jordanhill123 Sep 24 '14 at 02:40
  • @jordanhill123 it's not. That question was marked as 'answered' when the person was told how to disable warnings. I know how to do that. I need TFS TEAMBUILD controller to ignore these import statements. – zaitsman Sep 24 '14 at 02:46
  • 2
    Will this specific answer in that question assist? http://stackoverflow.com/a/21931371/749725 I don't use TFS so can't test it and unsure how it will handle this config file. – jordanhill123 Sep 24 '14 at 02:47
  • In case Jordans' answer doesn't suit you, perhaps you can consider replacing the import statement with a different import statement, pointing to some global file, that all your projects will use. That way, in the future, you will be able to control global settings for all your projects in a central place. I know it doesn't help you much now, but could be a good idea for the next time you'll have to do something like this. – Roman Sep 24 '14 at 09:26

2 Answers2

1

The StyleCop target, as defined in Microsoft.StyleCop.targets is conditional on property StyleCopEnabled.

Here is a snippet from Microsoft.StyleCop.targets:

<!-- Define target: StyleCop -->
<Target Name="StyleCop" Condition="'$(StyleCopEnabled)' != 'false'">
  <Message Text="Forcing full StyleCop reanalysis." Condition="'$(StyleCopForceFullAnalysis)' == 'true'" Importance="Low" />
  ... snip ...

The quick way to disable stylecop is to pass global setting for StyleCopEnabled. E.g. if you are building from command line, the command would be: msbuild MyProject.proj /p:StyleCopEnabled=false

seva titov
  • 11,720
  • 2
  • 35
  • 54
  • I tried specifying this in the MSBuild arguments for TFS and it ignored this for some reason. Of course, it may be that it is the problem with TFS. Also, does it need to have stylecop installed to recognise this flag? – zaitsman Sep 25 '14 at 01:13
  • @zaitsman, Your projects assume StyleCop is installed, and would fail the build if `Microsoft.StyleCop.targets` file is not found in the locations specified in element. The error code would be `MSB4019`. – seva titov Sep 25 '14 at 16:23
  • yeah I gathered that. The only way I could bypass this was by hand editing .csproj files for every project to remove this. What i'm looking for is some sort of automated way to achieve the same outcome. I can't install stylecop on the hosted build controller in tfs online. – zaitsman Sep 25 '14 at 23:46
0

I had a similiar problem, still manual editing, but this worked for me. Opened all of the .csproj file in notepad by searching in the directory of the projects, then selecting all and "Edit with Notepad++". Then do a Find-Replace with "Find All in All Open Documents" to remove the import line:

<Import Project="$(ProjectDir)\..\StyleCop.targets" Condition=" '$(OS)' == 'Windows_NT' " />
CodyF
  • 4,977
  • 3
  • 26
  • 38