2011-01-06 49 views
4

我試圖添加一個自動生成後觸發器來在TFS 2010中自動化團隊構建後運行NDepend(代碼度量軟件)。TFS 2010 /代碼度量集成,自動構建失敗,代碼度量不運行

NDepend的網站提供了集成此功能的代碼,因此我已將他們的代碼粘貼到我的.csproj文件中,他們表示要去,但我在構建時收到錯誤。

錯誤是指我在代碼片段中使用的三個「BuildStep」標記中的兩個。下面的兩個片段是給我的錯誤:

<BuildStep   
    TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
    BuildUri="$(BuildUri)" 
    Message="Running NDepend analysis"> 
    <Output TaskParameter="Id" PropertyName="StepId" /> 
</BuildStep> 

<BuildStep 
    TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
    BuildUri="$(BuildUri)" 
    Id="$(StepId)" 
    Status="Failed" /> 

然而,這個代碼片斷是不是扔了什麼問題:

<BuildStep 
    TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
    BuildUri="$(BuildUri)" 
    Id="$(StepId)" 
    Status="Succeeded" /> 

我只是不明白爲什麼一個工作正常,幾乎相同佈局的BuildStep標籤不會。有沒有簡單的,我只是俯瞰?

編輯:這裏是如何看起來都在一起,如果有差別:

<Target Name="NDepend" > 
    <PropertyGroup> 
     <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath> 
     <NDProject>$(SolutionDir)MyProject.ndproj</NDProject> 
     <NDOut>$(TargetDir)NDepend</NDOut> 
     <NDIn>$(TargetDir)</NDIn> 
    </PropertyGroup> 
    <Exec 
     Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/> 
    </Target> 
    <Target Name="AfterBuild"> 
    <BuildStep   TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
     BuildUri="$(BuildUri)" 
     Message="Running NDepend analysis"> 
     <Output TaskParameter="Id" PropertyName="StepId" /> 
    </BuildStep> 
    <PropertyGroup> 
     <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath> 
     <NDProject>$(SolutionRoot)\Main\src\MyProject.ndproj</NDProject> 
     <NDOut>$(BinariesRoot)\NDepend</NDOut> 
     <NDIn>$(BinariesRoot)\Release</NDIn> 
    </PropertyGroup> 
    <Exec 
     Command='$(NDPath) "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/> 
    <BuildStep 
     TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
     BuildUri="$(BuildUri)" 
     Id="$(StepId)" 
     Status="Succeeded" /> 
    <OnError ExecuteTargets="MarkBuildStepAsFailed" /> 
    </Target> 

    <Target Name="MarkBuildStepAsFailed"> 
    <BuildStep 
     TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
     BuildUri="$(BuildUri)" 
     Id="$(StepId)" 
     Status="Failed" /> 
    </Target> 

編輯:添加一個賞金,因爲我真的需要得到這個去爲我的球隊。

編輯:包括關於錯誤的更多細節,我爲版權原因僞裝文件的位置/名稱,我不知道如果我在技術上能夠釋放該信息,所以我我錯在安全而不是遺憾的一面,但如果你爲解決這個問題而絕對必須知道,我會看看我能做些什麼。在失敗的團隊構建的結果以及其他各種警告中列出了以下錯誤,但這些錯誤是我能看到的與上面的NDepend XML代碼有關的唯一錯誤。

C:*Blah*.csproj (172): The "BuildStep" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

C:*Blah*.csproj (194): The "BuildStep" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

編輯:

當我運行團隊生成我得到的錯誤,我想我有它運行的權利,但門檻不正確建設。儘管模仿@Ewald建議的XML,但它在構建時仍然會拋出上述錯誤。我按照我覺得應該努力調整如下所述代碼的屬性值:

<Target Name="NDepend" > 
    <PropertyGroup> 
     <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath> 
     <NDProject>$(SolutionDir)MyProject.ndproj</NDProject> 
     <NDOut>$(TargetDir)NDepend</NDOut> 
     <NDIn>$(TargetDir)</NDIn> 
    </PropertyGroup> 
    <Exec 
     Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/> 
    </Target> 

    <Target Name="AfterBuild"> 
    <BuildStep   
     TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
     BuildUri="$(BuildUri)" 
     Name="CallMyTarget" 
     Message="Call My Target" 
     Condition="'$(IsDesktopBuild)'!='true'"> 
     <Output TaskParameter="Id" PropertyName="StepId" /> 
    </BuildStep> 
    <CallTarget Targets="NDepend" ContinueOnError="false"/> 
    <BuildStep 
     TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
     BuildUri="$(BuildUri)" 
     Id="$(StepId)" 
     Status="Succeeded" 
     Condition="'$(IsDesktopBuild)'!='true'" /> 
    <OnError ExecuteTargets="FailStep" /> 
    </Target> 

    <Target Name="FailStep"> 
    <BuildStep 
     TeamFoundationServerUrl="$(TeamFoundationServerUrl)" 
     BuildUri="$(BuildUri)" 
     Id="$(StepId)" 
     Status="Failed" 
     Condition="'$(IsDesktopBuild)'!='true'" /> 
    </Target> 

不過,我也嘗試只是把這個代碼:

<Target Name="NDepend" > 
    <PropertyGroup> 
     <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath> 
     <NDProject>$(SolutionDir)MyProject.ndproj</NDProject> 
     <NDOut>$(TargetDir)NDepend</NDOut> 
     <NDIn>$(TargetDir)</NDIn> 
    </PropertyGroup> 
    <Exec 
     Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/> 
    </Target> 

和自動化建設進展良好,沒有錯誤,但NDepend沒有像預期的那樣運行。

如果在TFS2010和TFS2008中使用的XML模式有些細微差別,導致我出現這些問題,我開始懷疑(在諮詢了各種其他子問題之後)。那麼,考慮到這一點,是否有人知道這些模式中的任何重大差異?

編輯:只是讓你所有最新的一切,我已經試過了,我現在嘗試這種代碼:

<Target Name="AfterBuild"> 
    <PropertyGroup> 
     <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath> 
     <NDProject>$(SolutionDir)MyProject.ndproj</NDProject> 
     <NDOut>$(TargetDir)NDepend</NDOut> 
     <NDIn>$(TargetDir)</NDIn> 
    </PropertyGroup> 
    <Exec 
     Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/> 
</Target> 

和它產生了不同的錯誤信息,如下所示:

C:*Blah*.csproj (179): The command ""c:\tools\NDepend\NDepend.console.exe" "C:*Blah*\Sources\Main\MyProject.ndproj" /OutDir "C:*Blah*\Binaries\Debug\NDepend" /InDirs "C:*Blah*\Binaries\Debug\"" exited with code 1.

編輯:我試過的最新代碼。這是(根據NDepend的網站)「內置的NDepend MSBuild任務」。

<Target Name="AfterBuild"> 
    <PropertyGroup> 
     <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath> 
     <NDProject>$(SolutionDir)MyProject.ndproj</NDProject> 
     </PropertyGroup> 
     <UsingTask AssemblyFile="$(NDPath)\MSBuild\NDepend.Build.MSBuild.dll" 
      TaskName="NDependTask" /> 
     <Target Name="NDepend" > 
     <NDependTask NDependConsoleExePath="$(NDPath)" 
      ProjectFilePath="$(NDProject)" /> 
     </Target> 
</Target> 

但我得到這個錯誤:

C:*Blah*.csproj (180): The element beneath element is unrecognized.

+1

「我收到錯誤」 ......「給我的錯誤」 ......什麼*是*的錯誤? – AakashM 2011-01-10 20:13:26

+0

@AakashM,謝謝你指出,我完全忘了添加那個信息。我編輯了問題以包含我收到的錯誤消息,請讓我知道如果您需要其他任何東西! – AmbiguousX 2011-01-10 20:42:08

回答

0

的代碼片段,只有當你運行團隊建設工作。運行桌面版本時,它們可能會失敗。如果您使用Team Buid,您可以安全地刪除這些行,因爲他們所做的只是添加構建日誌的一行。

+0

但是我正在排隊我在TFS中設置的自動化構建,並且因爲上面提到的錯誤而失敗。這不是團隊建設嗎? – AmbiguousX 2011-01-07 14:45:08

1

我用下面的代碼行,以實現額外的生成步驟

<Target Name="Customization"> 
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="CallMyTarget" Message="Call my target" Condition="'$(IsDesktopBuild)'!='true'" > 
     <Output TaskParameter="Id" PropertyName="CurrentBuildStepId" /> 
    </BuildStep> 

    <CallTarget Targets="MyTarget" ContinueOnError="false"/> 

    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(CurrentBuildStepId)" Status="Succeeded" Condition="'$(IsDesktopBuild)'!='true'" /> 

    <OnError ExecuteTargets="FailStep"/> 
</Target> 

<Target Name="FailStep"> 
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(CurrentBuildStepId)" Status="Failed" Condition="'$(IsDesktopBuild)'!='true'" /> 
</Target> 
+0

謝謝你的代碼示例!現在,作爲一名初學者,我還有一個問題,如果你能夠/不介意,我希望你能提供一些信息:http://stackoverflow.com/questions/4660021/xml-tags-properties-and -their-definitions-please-read-before-deletion – AmbiguousX 2011-01-11 16:37:59

+0

不顧上述,有人已經回答了。感謝您的幫助! – AmbiguousX 2011-01-11 16:51:56

+0

對不起,但我刪除了「接受」,因爲它沒有正確運行。我原以爲是,但事實證明,它不能正確構建,或者沒有像應該那樣運行NDepend客戶端。請檢查最新的問題編輯,瞭解更多詳情。 – AmbiguousX 2011-01-11 20:27:13