Isn't working for me...

Jun 30, 2009 at 8:10 PM

I run Stylefix but my source files (with numerous StyleCop issues) remain unchanged - does this mean the Stylefix isn't finding the Microsoft StyleCop 4.3.1.3 dlls when it invokes MsBuild?

Jul 1, 2009 at 7:09 PM

Here is an error message from StyleFix for the above issue:

Unable to update the file C:\Visual Studio 2005\Projects\ConsoleApplication5\ConsoleApplication5\ConsoleApplication5.csproj: This document already has a 'DocumentElement' node.

Here is my project file (A plain vanilla VS 2005 console project)

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{90330542-81C8-4450-A6E8-6C6B4A1E006B}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>ConsoleApplication5</RootNamespace>
    <AssemblyName>ConsoleApplication5</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Jul 1, 2009 at 8:11 PM

I manually updated my project file to include the StyleCop target:

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

and now the StyleFix Enable StyleCop/Disable StyleCop buttons work as expected by updating the project file to:

<ExcludeFromStyleCop>false</ExcludeFromStyleCop> (or true)

BUT my original problem remains - when I press the Run StyleFix button, I get a message "Build Suceeded" but my source files (which have many StyleCop errors) NEVER change

Jul 1, 2009 at 8:27 PM
Edited Jul 1, 2009 at 8:36 PM

Here is the program source (an unchanged console app generated by VS 2005)

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

Jul 1, 2009 at 8:33 PM

Here is the build output (with StyleCop warnings)

------ Build started: Project: ConsoleApplication5, Configuration: Debug Any CPU ------

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /optimize- /out:obj\Debug\ConsoleApplication5.exe /target:exe Program.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings

ConsoleApplication5 -> C:\Visual Studio 2005\Projects\ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.exe

Properties\AssemblyInfo.cs(1,1): warning : SA1633: The file has no header, the header Xml is invalid, or the header is not located at the top of the file.

Program.cs(7,1): warning : SA1600: The class must have a documentation header.

Program.cs(9,1): warning : SA1600: The method must have a documentation header.

Program.cs(1,1): warning : SA1633: The file has no header, the header Xml is invalid, or the header is not located at the top of the file.

Program.cs(7,1): warning : SA1400: The class must have an access modifier.

Program.cs(9,1): warning : SA1400: The method must have an access modifier.

Program.cs(1,1): warning : SA1200: All using directives must be placed inside of the namespace.

Program.cs(2,1): warning : SA1200: All using directives must be placed inside of the namespace.

Program.cs(3,1): warning : SA1200: All using directives must be placed inside of the namespace.

Properties\AssemblyInfo.cs(31,1): warning : SA1120: The comment is empty. Add text to the comment or remove it.

Done building project "ConsoleApplication5.csproj".

========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Jul 1, 2009 at 8:58 PM

Eureka: If the file path to the project file contains spaces (e.g. C:\Program Files\...) the spawn of msbuild fails silently (Stylefix needs to wrap the path in quotes)

When the file path has no spaces, StyleFix works

Aug 26, 2009 at 4:06 PM

I download the source:

1) Fixed bug on msbuild spawn to put path in quotes - Add line to method GetInputString: projectFileName = "\"" + projectFileName + "\"";
2) StyleFix depends on running msbuild to generate StyleCop errors  - BUT could run StyleCop independantly of msbuild with command line StyleCop
3) Fixes only a small subset of list of violations (this is well documented)
4) some of the fixes sometimes don't work: e.g. 1501 if/then/else fix to put single line on multiple lines throws away else! (fixes Style violation but destroys code)

5) I will continue with bug fixes & enhancements as time permits

 

Jan 29, 2013 at 11:07 AM

when i tried to use Stylefix tool to remove stylecop errors then my code in .cs file are become twice .any body have any idea.

Jan 30, 2013 at 10:21 AM

i am using stylecop 4.7 and stylefix 0.6.When i tried to try to implement Stylefix it shows succeeded but in my code there is no change occurs.

plz suggest or reply as i want to implent this in my new project.

Thanks in advance.