惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - 黃偉榮

Web Project的檔案共用小技巧 IoC的中繼器:CommonServiceLocator UTF8Encoding與BOM Temporary Post Used For Theme Detection (d4b0aefa-c88e-4957-bba7-b367d1bfa042 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 寫CodedUI時如何尋找控制項的小技巧 Visual Studio 2010 Feature Packs 2之Silverlight自動化測試 Moles - Isolation framework for .NET(假.Net)介紹 [小技巧]Entity Framework強型別Include C#仿Oracle Decode,將ValueType對應成String - 黃偉榮 - 博客园 Visual Studio 單元測試的3種Initialize與Cleanup jQuery套件-檢查頁面的欄位是否有變更 用EventLogReader查詢特殊EventLog jQuery自製Plugin-Bind事件函式時檢查有沒有Bind過 ASP.NET MVC TempData使用心得 Visual Stuiod 自訂檔案比較合并工具 [小技巧]自動化測試時NLog的訊息輸出到測試結果中 小技巧:專案切換32與64位元組件 Linq小技巧:日期處理 Unit Test小技巧 : DateTime的Stub
解決TFS Build Asp.Net Mvc開啟MvcBuildViews後無法載入組件問題
黃偉榮 · 2010-09-10 · via 博客园 - 黃偉榮

為了在編譯時期就可以發現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

參考資料