2015-07-21 61 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,有/无自定义标签等)才能工作。 –

相关问题