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

推荐订阅源

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的訊息輸出到測試結果中 Linq小技巧:日期處理 Unit Test小技巧 : DateTime的Stub 解決TFS Build Asp.Net Mvc開啟MvcBuildViews後無法載入組件問題
小技巧:專案切換32與64位元組件
黃偉榮 · 2010-09-15 · via 博客园 - 黃偉榮

最近的一個專案中,有用到一個組件有分32位元與64位元,如Chilkat .NET,因為Visual Studio 2010是32位元,如果開發時用64位元的組件,會發生一些問題,如AspNetCompiler編譯失敗,還有MVC專案的View,在Design時發生載入組件錯誤,使得無法使用IntelliSense,所以開發時沒辦法只能用32位元的組件,但佈署時又不希望人工去替換組件,怎麼辦呢?

ViewFail

圖一 View在Desing時發生錯誤,使得無法使用IntelliSense。

事實上要達成在佈署時切換到64位元組件,還滿簡單的,只要對 .csproj 檔修改就可以了。

image

圖二 方案的檔案結構,Libs下放不分位元或32位元的組位,而其下64的資料夾,專門放有位元之分的64位元組件。

打開.csproj 檔,在參考組件的地方,可以改成如下。

<Project>
    ...
    <!--Debug時用32位元組件-->
    <Reference Include="ChilkatDotNet4" Condition=" '$(Configuration)' == 'Debug' ">
      <HintPath>..\Libs\ChilkatDotNet4.dll</HintPath>
    </Reference>
    <!--Release時用64位元組件-->
    <Reference Include="ChilkatDotNet4" Condition=" '$(Configuration)' == 'Release' ">
      <HintPath>..\Libs\64\ChilkatDotNet4.dll</HintPath>
    </Reference>
    ...
</Project>

當用Release模式Build時,使用64位元的組件,Bebug時用32位元組件,而佈署時使用Release模式佈署,就達到切換組件的效果。

Tip:

範例中下的限製條件比較少,如果你需要Release時還要可以選擇的話,可以把條件改成

<Reference Include="ChilkatDotNet4" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">

還有Mvc的專案,會希望Release時,編譯View,檢查錯誤,但因為預設是使用32位元的編譯器,也需要作修改。

<Project>
    ...
    <Target Name="AfterBuild" Condition=" '$(MvcBuildViews)' == 'true' ">
        <!--必需指定64位元編譯器的位址-->
        <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" ToolExe="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe" />
    </Target>
    ...
</Project>