解決TFS Build Asp.Net Mvc開啟MvcBuildViews後無法載入組件問題

來源:互聯網
上載者:User
文章目錄
  • 開啟MvcBuildViews

為了在編譯時期就可以發現View中的語法錯誤,我們會將MvcBuildViews設成true,但因為公司有使用TFS的MSBuild,會因為環境的關係而產生問題,如無法載入組件。

 

開啟MvcBuildViews

開啟.csproj檔案,打開的方式常見有這二種

  1. 直接用文字編輯器開啟(如Notepad)
  2. 載入後在Solution Explorer中專案上右鍵選擇Unload Project,卸載後在按一次右鍵選擇Edit *.csproj

 

原始的檔案內容

<Project ...>  ...  <MvcBuildViews>false</MvcBuildViews>  ...  <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />  </Target>  ...</Project>

 

將MvcBuildViews改成<MvcBuildViews>true</MvcBuildViews>後,每次在Visual Stuiod中Build後,會在把.aspx或.ascx等檔案也Build一次,以便及早發現錯誤。

Asp.Net Mvc的專案在Build時,預設只會Build *.cs、*.Designer.cs如Controller、Model等檔案,其他Views下的 *.aspx、*.ascx是不會被Build的,可就是說在.aspx如打錯字,也必需等到真正報行網站時,才會報錯,這種明明可以在Build期問就可以發現的問題,比一一執行網頁才能發現錯誤,有效率多了。

但同樣的設定在本機正常,但用TFS Build就會發生無法載入組件問題,原因是因為TFS MSBuild的設定,輸入的檔案與專案在不同位址,所以用$(ProjectDir)當然找不到bin與其下的dll,這樣就會發生本機與TFS的路徑問題,所以要加上IsDesktopBuild來分隔。

<Target Name="AfterBuild" Condition=" '$(MvcBuildViews)' == 'true' ">  <AspNetCompiler Condition="'$(IsDesktopBuild)' != 'false'" VirtualPath="temp" PhysicalPath="$(ProjectDir)" />  <AspNetCompiler Condition="'$(IsDesktopBuild)' == 'false'" VirtualPath="temp" PhysicalPath="$(OutDir)\_PublishedWebsites\$(ProjectName)" />   </Target> 

用Condition="'$(IsDesktopBuild)' == 'false'"來分隔,本機與TFS的MSBuild。

TFS MSBuild的資料夾結構

--[設定的Drop Folder]

----[Build AgentID]

------[Build Definition Name]

---------Binaries{$(OutDir)}

--------------_PublishedWebsites

-----------------------[Web Project]

--------------[Other Project]

---------Sourcees

--------------[Project]{$(ProjectDir)}

 

如果有一個Build Deinition

Name=TestBuild

Drop Folder=C:\Builds

BuildAgentID=1

所以執行時從Source Control下載專案到 C:\Builds\1\TestBuild\Sourcees,而Build後會將檔案輸出到Binaries中,而Web Project會放在Binaries\_PublishedWebsites下,所以必需指到其路徑才能正常的執行AfterBuild

 

參考資料

  •  Visual Sution 2010 版MS Build
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.