2017-05-05 143 views
0

因此,我嘗試將一個簡單的C#Web API項目部署到Azure中。該項目在本地構建並運行良好(不總是?!?),但在Azure中,由於缺少使用的Microsoft.ServiceBus程序集,因此它失敗。Azure部署由於缺少程序集引用而失敗

這個項目的結構非常簡單:

\ 
--\Common 
----MyProj.common.dll << This uses Microsoft.ServiceBus and has its own packages.config with WindowsAzure.ServiceBus referenced 
--\Web 
----MyProj.Api << This has an assembly reference to MyProj.common.dll. It doesn't have a reference to WindowsAzure.ServiceBus itself (although I added one to see if it helped, but it didn't) 

從Azure的部署腳本的輸出如下:

Command: "D:\home\site\deployments\tools\deploy.cmd" 
Handling ASP.NET Core Web Application deployment. 
    Restoring packages for D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj... 
    Installing WindowsAzure.ServiceBus 4.0.0. 
    Writing lock file to disk. Path: D:\home\site\repository\MyProj\Web\MyProj.Api\obj\project.assets.json 
    Restore completed in 12.73 sec for D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj. 

    NuGet Config files used: 
     D:\local\AppData\NuGet\NuGet.Config 

    Feeds used: 
     https://api.nuget.org/v3/index.json 

    Installed: 
     1 package(s) to D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj 
Microsoft (R) Build Engine version 15.1.548.43366 
Copyright (C) Microsoft Corporation. All rights reserved. 

D:\Program Files (x86)\dotnet\sdk\1.0.1\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.ServiceBus, Version=3.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. [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj] 
Azure\AQM.cs(7,17): error CS0234: The type or namespace name 'ServiceBus' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj] 

Azure\AQM.cs(8,17): error CS0234: The type or namespace name 'ServiceBus' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj] 
Azure\AQM.cs(14,17): error CS0246: The type or namespace name 'NamespaceManager' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj] 
D:\Program Files (x86)\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for 'D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj'. This can indicate a missing project reference. [D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj] 
Failed exitCode=1, command=dotnet publish "MyProj\Web\MyProj.Api\MyProj.Api.csproj" --output "D:\local\Temp\8d493823074840c" --configuration Release 
An error has occurred during web site deployment. 
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\62.60430.2807\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd" 

我在任何時候注意到它試圖恢復包爲常見程序集 - 我如何'告訴'Azure做到這一點?這甚至是問題嗎?

編輯1

考慮使用捻部署腳本,它似乎是在做一個解決方案廣泛的恢復,所以不知道如何/爲什麼會出現缺少組裝參考:

:: 1. Restore nuget packages 
call :ExecuteCmd dotnet restore "MyProj\MyProj.sln" 
IF !ERRORLEVEL! NEQ 0 goto error 

謝謝

回答

0

我注意到它在任何時候都沒有嘗試恢復Common程序包 - 我如何'告訴'Azure做到這一點?這甚至是問題嗎?

根據您的描述,您的項目是.net核心項目。

您提到Servicebus Libriary(WindowsAzure.ServiceBus 4.0.0)不是.NET Core兼容的。而新的Libriary,即預發佈版本,是100%兼容的。我們可以得到更多的細節here

我們還可以從另一個SO thread找到它。

編輯:

根據您的評論我更新的答案:

我也嘗試創建C#的Web API項目,並部署到Azure中是否能夠正常工作在我的身邊。

請嘗試清理構建並重新使用新的WebApp重新構建項目。

以下是我的詳細步驟:

1,創建一個類libiary項目命名公共與功能GetQueue

enter image description here

2.創建Web應用程序項目和參考通用公共ServiceBusHelper類.dll和Microsoft.ServiceBus.dll,然後更改getvaules函數以獲取隊列

public List<QueueDescription> Get() 
     { 
      var queueList = Common.ServiceBusHelper.GetQueueList(); 
      return queueList; 
     } 

3.在將WebApi發佈到Azure期間從Auzre WebApp中刪除現有文件

4。測試Web應用程序

enter image description here

+0

對不起湯姆,是我不好。它的全部.net(4.6.2)。 – LDJ

+0

更新回答,更多詳細資料請參閱。 –