Asp.net-Mvc

Azure git 部署-第二個程序集中缺少引用

  • April 27, 2013

我正在嘗試將 Bitbucket 部署設置到 Azure 網站。我成功連結了 Bitbucket 和 Azure,但是當我推送到 Bitbucket 時,我在 Azure 站點上收到以下錯誤:

在此處輸入圖像描述

如果我點擊“查看日誌”,則會顯示以下編譯錯誤:

   D:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   D:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   CustomMembershipProvider.cs(5,7): error CS0246: The type or namespace name 'WebMatrix' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   CustomMembershipProvider.cs(9,38): error CS0246: The type or namespace name 'ExtendedMembershipProvider' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   Models\AccountModels.cs(3,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   CustomMembershipProvider.cs(198,37): error CS0246: The type or namespace name 'OAuthAccountData' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   Models\AccountModels.cs(40,10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   Models\AccountModels.cs(40,10): error CS0246: The type or namespace name 'CompareAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   Models\AccountModels.cs(73,10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
   Models\AccountModels.cs(73,10): error CS0246: The type or namespace name 'CompareAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]

請注意,這些編譯錯誤針對我項目中的另一個程序集(我放置業務邏輯的程序集)。

Google搜尋時,我發現的唯一提及是必須將這些引用的“本地副本”標誌設置為 true。我已經嘗試過了,但仍然遇到相同的錯誤。

這一切都在本地編譯得很好。有任何想法嗎?

更新

為了添加更多資訊,我在 Git 儲存庫中的項目結構如下:

+ProjName
   ProjName.csproj
   web.config
   ...etc...
+ProjName.Common
   ProjName.Common.csproj
+ProjName.Tests
   ProjName.Tests.csproj
+packages <-- these are Nuget packages
ProjName.sln

Azure 顯示的編譯錯誤表明失敗的是 ProjName.vcproj - 但它們指的是 ProjName.Common 程序集參考。

請注意,此佈局是 VisualStudio 創建的(即 webroot 的額外項目子目錄)。

我不確定 Azure 在進行 Git 部署時會做什麼。它是否認識到 ProjName 目錄是 webroot,並且還解析 ProjName.sln 編譯解決方案中的任何其他程序集(與 Visual Studio 相同)?

另外,我沒有向 Git 添加任何“bin”文件夾。但是,我只是將其作為測試進行了嘗試,它並沒有改變 Azure 產生的編譯錯誤。

2012 年 11 月 25 日更新:查看 Dan 的 repo 後,問題是庫項目使用 GAC 中的 Mvc 4 而不是使用 NuGet 包。切換到 NuGet 包可以使其在 Azure 上正常工作。

理論上,MVC4 可以在 Azure 機器上的 GAC 中,這不是問題。也許他們會在某個時候到達那裡。雖然一般來說,MVC 團隊越來越多地推動基於 NuGet 的模型,您不依賴於 GAC 中的內容。

原答案:

通常,您應該避免將二進製文件送出到您的 git 儲存庫,而是依靠 NuGet 來檢索它們。請參閱https://github.com/KuduApps/Mvc4ApplicationFx40WithLib以獲取執行此操作並在 Azure 網站中正常工作的範例項目。

但根據您的項目結構,我看到您的項目似乎使用 C++ (.vcproj)。如果是這樣,那麼可能的問題是今天通過 git 發佈時,Azure 網站可能不支持 C++。到目前為止,我不認為人們必須使用 C# 和 VB。如果這確實是問題,那麼我建議您在https://github.com/projectkudu/kudu上打開一個問題,以便我們可以正確跟踪它。

引用自:https://stackoverflow.com/questions/13429867