gpt4 book ai didi

c# - 由于缺少程序集引用,Azure 部署失败

转载 作者:行者123 更新时间:2023-12-02 07:28:52 26 4
gpt4 key购买 nike

所以我有一个简单的 C# Web API 项目,我正在尝试将其部署到 Azure 中。该项目在本地构建并运行良好(不是总是这样吗?!?),但在 Azure 中,由于缺少使用的 Microsoft.ServiceBus 程序集而失败。

项目结构非常简单:

\
--\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

查看使用 Kudu 的部署脚本,它似乎正在执行解决方案范围的恢复,因此不确定如何/为什么缺少程序集引用:

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

谢谢

最佳答案

I notice at no point does it attempt to restore the package for the Common assembly - how do I 'tell' Azure to do this? And is this even the issue?

根据您的描述,您的项目是.net core项目。

您提到Servicebus Libriary (WindowsAzure.ServiceBus 4.0.0) 与 .NET Core 不兼容。和新的Libriary ,这是预发布版本,100% 兼容。我们可以获取更多详细信息here .

我们也可以从另一个SO thread找到它.

编辑:

根据您的评论我更新答案:

我还尝试创建 C# Web API 项目并将其部署到 Azure,它在我这边工作正常。

请尝试清理构建并使用新的 WebApp 再次重建项目。

以下是我的详细步骤:

1.创建一个名为common的类库项目和一个具有GetQueue函数的公共(public)ServiceBusHelper类

enter image description here

2.创建一个WebApp项目并引用Common.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

关于c# - 由于缺少程序集引用,Azure 部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43798596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com