[英]How to run Qt application from Visual Studio 2019 targeting WSL
[英]How can I deploy a Blazor server-hosted application from Visual Studio 2019
我正在使用VS2019預覽版。 我使用最新的Blazor擴展(16.0.19227)創建了一個“服務器托管的”Blazor應用程序。 這是包含3個獨立項目的變體......
我可以通過制作MyApp來調試它。 服務器活動項目,一切正常,但我很難將此發布/部署到Azure。 我試過以下......
此時我在部署期間遇到錯誤...
CSC(0,0):錯誤CS0006:無法找到元數據文件'D:\\ work \\ Applications \\ Web \\ MyApp.Client \\ bin \\ Release \\ netstandard2.0 \\ win-x86 \\ MyApp.Client.dll'
這似乎是因為Web部署配置文件中的“目標運行時”設置為win-x86 。 客戶端應用程序實際上正在構建為
“d:\\工作\\應用程序\\網絡\\ MyApp.Client \\ BIN \\發布\\ netstandard2.0 \\ MyApp.Client.dll”
(沒有額外的win-x86子文件夾)所以部署過程似乎對構建過程使用的路徑做出了錯誤的假設。 發布對話框中無法指定空白/不關心目標運行時。
是否有針對此的解決方法,或者我使用錯誤的方法進行部署?
有一些官方文檔,但它不是很有幫助。
更新似乎部署正在使用Client項目的輸出路徑,然后只是將netstandard2.0 {Target Runtime}附加到它,因此更改Client項目中的輸出路徑不足以解決此問題。
更新2通過編輯xml刪除發布配置文件中的RuntimeIdentifier標記只會導致部署時錯誤,指出空的RuntimeIdentifier與自包含部署不兼容。 不幸的是,自包含部署是必要的,因為Azure尚未直接托管.net核心3。
因為Azure尚未直接托管.net核心3。
但確實如此。
在Azure門戶中,部署后轉到WebApp(或預先創建一個)。
轉到Extensions並單擊Add [ + ]並選擇ASP.NET Core 3(免費托管的x86)。
另請轉到“設置”,“常規”並啟用WebSockets,默認情況下它們處於關閉狀態。
請注意,Preview-6不可用作擴展,因此要么使用Preview-5,要么部署為自包含。
我的回答是:
<TargetFramework>...</TargetFramework>
節點名稱更改為<TargetFrameworks>...</TargetFrameworks>
。 (另見: https : //stackoverflow.com/a/42855070 ) Startup
類中運行時修復Web根文件夾路徑字符串,如下所示。 using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json.Serialization;
using System.IO;
using System.Linq;
namespace BlazorHostedOnAzure.Server
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddNewtonsoftJson();
services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseResponseCompression();
// ---- APPEND PART.1 BEGIN ----
var clientBlazorWebRootPath = default(string);
// ---- APPEND PART.1 END ----
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBlazorDebugging();
}
// ---- APPEND PART.2 BEGIN ----
else
{
if (env.WebRootPath != null)
{
var pathOfIndex = Path.Combine(env.WebRootPath, "index.html");
var pathOfContent = Path.Combine(env.WebRootPath, "_content");
if (!File.Exists(pathOfIndex) && Directory.Exists(pathOfContent))
{
clientBlazorWebRootPath = Directory.GetDirectories(pathOfContent).FirstOrDefault();
if (clientBlazorWebRootPath != null)
{
env.WebRootPath = clientBlazorWebRootPath;
}
}
}
}
// ---- APPEND PART.2 END ----
app.UseClientSideBlazorFiles<Client.Startup>();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
});
// ---- APPEND PART.3 BEGIN ----
if (clientBlazorWebRootPath != null)
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(clientBlazorWebRootPath)
});
}
// ---- APPEND PART.3 BEGIN ----
}
}
}
我在GitHub我的存儲庫上發布了示例代碼和README。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.