2015-07-21 64 views
4

我想在驗證我的.csproj文件時將它們添加到解決方案中,或者當它們構建在我們的CI構建服務器上時。驗證解決方案中的.csproj文件

驗證就意味着檢查,例如:

  • 路徑和項目文件名匹配約定
  • 大會名稱和命名空間匹配的命名約定
  • ,該平臺的目標是正確的
  • 輸出路徑正確(Release and Debug)
  • 警告級別正確,警告被視爲錯誤
  • 某些文件出現在項目中(AssemblyInfo.cs等)。
  • 該組件已經被正確引用

另一個有用的功能是忽略某些項目的能力,或者更好的是,要能夠確定項目的分組具有它自己的驗證每組規則。

在我看來,這似乎是許多其他人必須具備的問題,但我還沒有找到任何工具可以幫助簡化或自動化此過程。我想它可能就像StyleCop或FxCop。

這樣的工具是否存在或者我是否必須創建自己的自定義構建步驟?

(我也使用ReSharper的,所以會考慮插件,雖然這可能使構建服務器更困難的驗證。)

回答

1

AFAIK沒有tool to achieve this。這就是爲什麼我的一個collague編碼自定義工具來驗證.csproj.vbproj文件與自定義規則驗證程序。

例如,有一些類可以檢查項目文件,例如Microsoft.Build.Evaluation.Project(程序集Microsoft.Build),這些文件可能對您很方便。但是當你試圖解析解決方案文件時,它會變得很髒。我強烈建議看看這個question on StackOverflow

的公司內部驗證工具,我只是在談論檢查定義的規則(如ToolsVersionTargetFrameworkVersionTargetCPU,...)並繪製在格式對應的輸出,使構建服務器可以解析消息並停止如果一個重要的規則被打破,那就是一個構建

祝你好運!

-2

你將不得不自己製作一個程序。 這是一個.csproj文件的例子。 您必須閱讀並查看數據,確保程序正確無誤。

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<PropertyGroup> 
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> 
    <ProjectGuid>$guid1$</ProjectGuid> 
    <ProjectTypeGuids>{EE2C853D-36AF-4FDB-B1AD-8E90477E2198};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> 
    <OutputType>Exe</OutputType> 
    <RootNamespace>$safeprojectname$</RootNamespace> 
    <AssemblyName>$safeprojectname$</AssemblyName> 
    <IPhoneResourcePrefix>Resources</IPhoneResourcePrefix> 
     <AppDesignerFolder>Properties</AppDesignerFolder> 
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> 
    <DebugSymbols>true</DebugSymbols> 
    <DebugType>full</DebugType> 
    <Optimize>false</Optimize> 
    <OutputPath>bin\iPhoneSimulator\Debug</OutputPath> 
    <DefineConstants>DEBUG</DefineConstants> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    <ConsolePause>false</ConsolePause> 
     <MtouchArch>i386, x86_64</MtouchArch> 
    <MtouchLink>None</MtouchLink> 
    <MtouchDebug>true</MtouchDebug> 
     <CodesignEntitlements>Entitlements.plist</CodesignEntitlements> 
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' "> 
    <DebugType>none</DebugType> 
    <Optimize>true</Optimize> 
    <OutputPath>bin\iPhoneSimulator\Release</OutputPath> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    <MtouchLink>None</MtouchLink> 
     <MtouchArch>i386, x86_64</MtouchArch> 
     <ConsolePause>false</ConsolePause> 
     <CodesignEntitlements>Entitlements.plist</CodesignEntitlements> 
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' "> 
    <DebugSymbols>true</DebugSymbols> 
    <DebugType>full</DebugType> 
    <Optimize>false</Optimize> 
    <OutputPath>bin\iPhone\Debug</OutputPath> 
    <DefineConstants>DEBUG</DefineConstants> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    <ConsolePause>false</ConsolePause> 
     <MtouchArch>ARMv7, ARM64</MtouchArch> 
     <CodesignEntitlements>Entitlements.plist</CodesignEntitlements> 
    <CodesignKey>iPhone Developer</CodesignKey> 
     <MtouchDebug>true</MtouchDebug> 
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' "> 
    <DebugType>none</DebugType> 
    <Optimize>true</Optimize> 
    <OutputPath>bin\iPhone\Release</OutputPath> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
     <CodesignEntitlements>Entitlements.plist</CodesignEntitlements> 
     <MtouchArch>ARMv7, ARM64</MtouchArch> 
    <ConsolePause>false</ConsolePause> 
    <CodesignKey>iPhone Developer</CodesignKey> 
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' "> 
    <DebugType>none</DebugType> 
    <Optimize>True</Optimize> 
    <OutputPath>bin\iPhone\Ad-Hoc</OutputPath> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    <ConsolePause>False</ConsolePause> 
     <MtouchArch>ARMv7, ARM64</MtouchArch> 
     <CodesignEntitlements>Entitlements.plist</CodesignEntitlements> 
    <BuildIpa>True</BuildIpa> 
     <CodesignProvision>Automatic:AdHoc</CodesignProvision> 
     <CodesignKey>iPhone Distribution</CodesignKey> 
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' "> 
    <DebugType>none</DebugType> 
    <Optimize>True</Optimize> 
    <OutputPath>bin\iPhone\AppStore</OutputPath> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    <ConsolePause>False</ConsolePause> 
     <MtouchArch>ARMv7, ARM64</MtouchArch> 
     <CodesignEntitlements>Entitlements.plist</CodesignEntitlements> 
     <CodesignProvision>Automatic:AppStore</CodesignProvision> 
    <CodesignKey>iPhone Distribution</CodesignKey> 
</PropertyGroup> 
<ItemGroup> 
    <Compile Include="Main.cs" /> 
    <Compile Include="AppDelegate.cs" /> 
    <None Include="Info.plist"/> 
    <Compile Include="Properties\AssemblyInfo.cs" /> 
    <Compile Include="RootViewController.designer.cs"> 
     <DependentUpon>RootViewController.cs</DependentUpon> 
    </Compile> 
    <Compile Include="RootViewController.cs" /> 
    <InterfaceDefinition Include="MainInterface.storyboard" /> 
</ItemGroup> 
<ItemGroup> 
    <Reference Include="System" /> 
    <Reference Include="System.Xml" /> 
    <Reference Include="System.Core" /> 
    <Reference Include="Xamarin.iOS" /> 
</ItemGroup> 
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" /> 

+0

這似乎是不正確;早期的答案提到使用特定的Microsoft庫來解析.csproj文件。我的問題實際上是要求使用工具來避免解析專有XML的確切問題(您的示例只是一種可能性 - 它必須跨越多個.csproj,有/無自定義標籤等)才能工作。 –

相關問題