å æ¥ãªã¼ãã³ã½ã¼ã¹ã«ãªã£ãStyleCop*1ãã¤ã³ã¹ãã¼ã«ãã¦å°ã使ã£ã¦ã¿ã¾ããã®ã§ãã¡ã¢ã£ã¦ããã¾ãã
ç°å¢ã¯Microsoft Visual C# 2010 Expressã§ãã
2008ãããã¯2010ã®Professional以ä¸ãªãVisual Studioã«çµ±åãããã¨ãå¯è½ã§ãã
ãã¦ã³ãã¼ã
å®å®çã¯4.3.3ã¨ãããã¨ã§ãããVisual Studio 2010ã«æ£å¼ã«å¯¾å¿ãã¦ããã®ã¯ç¾å¨ãã¼ã¿çã®4.4ã¨ãããã¨ãªã®ã§ã4.4ã使ããã¨ã«ãã¾ãã
4.3.3ã使ãã¨ããToolsVersionã®4.0*2ãªãã¦ç¥ããªããã3.5*3ã¨è¦ãªãã¦ãã§ãã¯ãããããã¿ãããªã¡ãã»ã¼ã¸ã表示ããã¾ãã
ãã¼ã¸ã§ã³4.4.0.9
ãã¼ã¸ã§ã³4.3.3
StyleCopã®ã¤ã³ã¹ãã¼ã«
Microsoft.StyleCop.msi ãããã«ã¯ãªãã¯ãã¦ã¤ã³ã¹ãã¼ã©ãèµ·åãã¾ãã
åºæ¬çã«ãã¤ã³ã¹ãã¼ã©ã«å¾ã£ã¦ãNextããã¿ã³ãæ¼ãã ãã§ããããCustom Setupãã®ç»é¢ã§ããMSBuild integration filesãã«ãã§ãã¯ãå ¥ããã®ã ã注æãå¿ è¦ã§ãã
Professional以ä¸ãã¤ã³ã¹ãã¼ã«ããã¦ããå ´å
以ä¸ã®æ§ã«Visual Studioã¨ã®é£æºã«é¢ããé
ç®ã表示ããã¾ãã
StyleCopã«ãã§ãã¯ãããããã®è¨å®
ããã¸ã§ã¯ããã¡ã¤ã«ï¼*.csprojï¼ãéããStyleCopã®è¨å®ãã¤ã³ãã¼ãããããã«ãã¾ãã
ç·¨éå¾
2è¡ç®ã追å ãã¾ãã
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(ProgramFiles)\MSBuild\Microsoft\StyleCop\v4.4\Microsoft.StyleCop.targets" />
â»4.3ã使ç¨ããå ´åã¯ãv4.4ãã®ç®æããv4.3ãã«å¤æ´ãã¾ã
ãã§ãã¯ãã¦ãããã
è¨å®ãçµããã°ãã«ãããã ãã§ãã
ãµã³ãã«ã½ã¼ã¹
using System; using System.Linq; using System.Text; namespace ClassLibrary1 { public class Class1 { private int _hoge; public void Fuga() { } } }
ããããã«ãããã¨â¦
ãã«ãçµæ
------ ãã«ãéå§: ããã¸ã§ã¯ã: ClassLibrary1, æ§æ: Release Any CPU ------ D:\Data\VS2010Projects\ClassLibrary1\Class1.cs(9,21): è¦å CS0169: ãã£ã¼ã«ã 'ClassLibrary1.Class1._hoge' ã¯ä½¿ç¨ããã¾ããã§ããã ã³ã³ãã¤ã«ã®å®äº -- ã¨ã©ã¼ 0ãè¦å 1 ClassLibrary1 -> D:\Data\VS2010Projects\ClassLibrary1\bin\Release\ClassLibrary1.dll 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. Class1.cs(7,1): warning : SA1600: The class must have a documentation header. Class1.cs(9,1): warning : SA1600: The field must have a documentation header. Class1.cs(11,1): warning : SA1600: The method must have a documentation header. Class1.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. Class1.cs(9,1): warning : SA1309: Field names must not start with an underscore. Class1.cs(1,1): warning : SA1200: All using directives must be placed inside of the namespace. Class1.cs(2,1): warning : SA1200: All using directives must be placed inside of the namespace. Class1.cs(3,1): warning : SA1200: All using directives must be placed inside of the namespace. ========== ãã«ã: æ£å¸¸çµäºã¾ãã¯ææ°ã®ç¶æ 1ã失æ 0ãã¹ããã 0 ==========
è±æãè¦ãã°è¨ããã¨ãã¦ãããã¨ã¯ã ãããåããã¾ããã詳細ã¯ä¸è¨ãã«ãã«è¼ã£ã¦ãã¾ãã
C:\Program Files\MSBuild\Microsoft\StyleCop\v4.4\Docs\StyleCop.chm
ä¸è¦ãªãã§ãã¯ãå¤ã
ãã§ãã¯ã®å 容ãæ°ã«å ¥ããªãå ´åã«ã¯ãç¹å®ã«ã¼ã«ã ããã§ãã¯ãããªãããã«ãã§ãã¾ãã
C:\Program Files\MSBuild\Microsoft\StyleCop\v4.4 é
ä¸ã«ãã StyleCopSettingsEditor.exe ã§ã«ã¹ã¿ãã¤ãºãã§ãã¾ãã
åãã©ã«ãã«ãã Settings.StyleCop ãããã«ã¯ãªãã¯ãã¾ãã*4
ãã¨ã¯ãç¡è¦ãããã«ã¼ã«ã®ãã§ãã¯ãå¤ãã¦ãã¾ãã ãã§ããã
ç¹å®ã®ã¯ã©ã¹ã ãã«ã¼ã«ãç¡è¦ãã
以ä¸ã®ããã«è¨è¿°ããã°ãç¹å®ã®ã¯ã©ã¹ã ãã«ã¼ã«ãç¡è¦ããããã«ãã§ãã¾ãã
SA1600ã«é¢ããã«ã¼ã«ãç¡è¦ããä¾
namespace ClassLibrary1 { using System; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented")] public class Class1 { private int _hoge; public void Fuga() { } } }
ãã®ãããã®ãã¨ã StyleCop.chm ã«å°ãè¼ã£ã¦ã¾ãã
ç¹å®ã®ãã¡ã¤ã«ããã§ãã¯å¯¾è±¡ããå¤ã
ç¹å®ã®ãã¡ã¤ã«ã®ã¿ãã§ãã¯ãããªãããã«ãããã¨ãåºæ¥ã¾ãã
ããã¸ã§ã¯ããã¡ã¤ã«ï¼*.csprojï¼ã®Compileã§æå®ããã¦ãã該å½ã®ãã¡ã¤ã«ã以ä¸ã®æ§ã«å¤æ´ãã¾ãã
å¤æ´å
<ItemGroup> <Compile Include="Class1.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup>
å¤æ´å¾
<ItemGroup> <Compile Include="Class1.cs" /> <Compile Include="Properties\AssemblyInfo.cs" > <ExcludeFromStyleCop>true</ExcludeFromStyleCop> </Compile> </ItemGroup>
æå¾ã«
SytleCopã«é¢ããããã°
ææ
- ã³ã¼ãã£ã³ã°è¦ç´ã®ãã§ãã¯ãèªååã§ããã®ã§ããã¼ã éçºã®æã«ã¯ä¾¿å©ï¼å½ããå
- å人çã«ãã§ãã¯ãããææç©ããªãã®ã«å¾ã§æ°ãã¤ããorzâ¦
*1:éç解æãã¼ã«
*2:Visual Studio 2010
*3:Visual Studio 2008 SP1?
*4:ãããã¯ã StyleCopSettingsEditor.exe ã«Dï¼Dãã