Azure部署由于缺少程序集引用而失败

Azure部署由于缺少程序集引用而失败

问题描述:

因此,我尝试将一个简单的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 

谢谢

我注意到它在任何时候都没有尝试恢复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

更新回答,更多详细资料请参阅。 –