我目前无法使用 .NET Core 3 预览版和 Visual Studio 2019 预览版(最新版本,刚刚下载)编译我的 Blazor 应用程序
我只创建了几个文件。
主布局模型.cs(在共享文件夹中)
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ICSSNetwork
{
public class MainLayoutModel : LayoutComponentBase
{
[Inject] protected AppState AppState { get; set; }
protected async Task Logout()
{
await AppState.Logout();
}
}
}
登录详细信息.cs(项目根目录)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ICSSNetwork
{
public class LoginDetails
{
public string Username { get; set; }
public string Password { get; set; }
}
}
AppState.cs (Project Root)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Helpers;
namespace ICSSNetwork
{
public class AppState
{
private readonly HttpClient _httpClient;
// private readonly ILocalStorage _localStorage;
public bool IsLoggedIn { get; private set; }
public AppState(HttpClient httpClient)
// ILocalStorage localStorage)
{
_httpClient = httpClient;
//_localStorage = localStorage;
}
public async Task Login(LoginDetails loginDetails)
{
//var response = await _httpClient.PostAsync(Urls.Login, new StringContent(Json.Serialize(loginDetails), Encoding.UTF8, "application/json"));
if (loginDetails.Password == "TEST123")
{
//await SetAuthorizationHeader();
IsLoggedIn = true;
}
}
public async Task Logout()
{
//await _localStorage.RemoveItem("authToken");
IsLoggedIn = false;
}
//private async Task SaveToken(HttpResponseMessage response)
//{
// var responseContent = await response.Content.ReadAsStringAsync();
// var jwt = Json.Deserialize<JwToken>(responseContent);
// await _localStorage.SetItem("authToken", jwt.Token);
//}
//private async Task SetAuthorizationHeader()
//{
// if (!_httpClient.DefaultRequestHeaders.Contains("Authorization"))
// {
// var token = await _localStorage.GetItem<string>("authToken");
// _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
// }
//}
}
}
当我第一次创建项目时,我构建了它,它构建得很好。添加这些文件后,我收到以下构建错误:
Error MSB3073 The command "dotnet "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor.mono3.0.0-preview8.19380.1buildnetstandard1.0../../tools/illink/illink.dll" -l none --disable-opt unreachablebodies --verbose --strip-security true --exclude-feature com --exclude-feature sre -v false -c link -u link -b true -d "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor.mono3.0.0-preview8.19380.1buildnetstandard1.0../../tools/mono/bcl/" -d "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor.mono3.0.0-preview8.19380.1buildnetstandard1.0../../tools/mono/bcl/Facades/" -o "C:UsersadamcDesktopICSSNetworkManagerICSSNetworkICSSNetworkobjDebugnetstandard2.0blazorlinker/" -x "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor.build3.0.0-preview8.19405.7targetsBuiltInBclLinkerDescriptor.xml" -x "C:UsersadamcDesktopICSSNetworkManagerICSSNetworkICSSNetworkobjDebugnetstandard2.0blazorlinker.descriptor.xml" -a "C:Usersadamc.nugetpackagesblazored.localstorage2.0.12libnetstandard2.0Blazored.LocalStorage.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnet.razor3.2.7libnet45System.Web.Razor.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnet.webpages3.2.7libnet45System.Web.Helpers.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnet.webpages3.2.7libnet45System.Web.WebPages.Deployment.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnet.webpages3.2.7libnet45System.Web.WebPages.Razor.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnet.webpages3.2.7libnet45System.Web.WebPages.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.authorization3.0.0-preview8.19405.7libnetstandard2.0Microsoft.AspNetCore.Authorization.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor3.0.0-preview8.19405.7libnetstandard2.0Microsoft.AspNetCore.Blazor.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor.httpclient3.0.0-preview8.19405.7libnetstandard2.0Microsoft.AspNetCore.Blazor.HttpClient.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.components3.0.0-preview8.19405.7libnetstandard2.0Microsoft.AspNetCore.Components.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.components.web3.0.0-preview8.19405.7libnetstandard2.0Microsoft.AspNetCore.Components.Web.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.metadata3.0.0-preview8.19405.7libnetstandard2.0Microsoft.AspNetCore.Metadata.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.bcl.asyncinterfaces1.0.0-preview8.19405.3libnetstandard2.0Microsoft.Bcl.AsyncInterfaces.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.extensions.dependencyinjection3.0.0-preview8.19405.4libnetstandard2.0Microsoft.Extensions.DependencyInjection.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.extensions.dependencyinjection.abstractions3.0.0-preview8.19405.4libnetstandard2.0Microsoft.Extensions.DependencyInjection.Abstractions.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.extensions.logging.abstractions3.0.0-preview8.19405.4libnetstandard2.0Microsoft.Extensions.Logging.Abstractions.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.extensions.options3.0.0-preview8.19405.4libnetstandard2.0Microsoft.Extensions.Options.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.extensions.primitives3.0.0-preview8.19405.4libnetstandard2.0Microsoft.Extensions.Primitives.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.jsinterop3.0.0-preview8.19405.4libnetstandard2.0Microsoft.JSInterop.dll" -a "C:Usersadamc.nugetpackagesmicrosoft.web.infrastructure1.0.0libnet40Microsoft.Web.Infrastructure.dll" -a "C:Usersadamc.nugetpackagesmono.webassembly.interop3.0.0-preview8.19405.4libnetstandard2.0Mono.WebAssembly.Interop.dll" -a "C:Program FilesdotnetsdkNuGetFallbackFoldersystem.buffers4.5.0libnetstandard2.0System.Buffers.dll" -a "C:Usersadamc.nugetpackagessystem.componentmodel.annotations4.6.0-preview8.19405.3libnetstandard2.0System.ComponentModel.Annotations.dll" -a "C:Usersadamc.nugetpackagessystem.memory4.5.3libnetstandard2.0System.Memory.dll" -a "C:Program FilesdotnetsdkNuGetFallbackFoldersystem.numerics.vectors4.5.0libnetstandard2.0System.Numerics.Vectors.dll" -a "C:Usersadamc.nugetpackagessystem.runtime.compilerservices.unsafe4.6.0-preview8.19405.3libnetstandard2.0System.Runtime.CompilerServices.Unsafe.dll" -a "C:Usersadamc.nugetpackagessystem.text.encodings.web4.6.0-preview8.19405.3libnetstandard2.0System.Text.Encodings.Web.dll" -a "C:Usersadamc.nugetpackagessystem.text.json4.6.0-preview8.19405.3libnetstandard2.0System.Text.Json.dll" -a "C:Usersadamc.nugetpackagessystem.threading.tasks.extensions4.5.2libnetstandard2.0System.Threading.Tasks.Extensions.dll" -a "C:UsersadamcDesktopICSSNetworkManagerICSSNetworkICSSNetworkobjDebugnetstandard2.0ICSSNetwork.dll"" exited with code -532462766. ICSSNetwork C:Usersadamc.nugetpackagesmicrosoft.aspnetcore.blazor.build3.0.0-preview8.19405.7targetsBlazor.MonoRuntime.targets 441
有人知道可能导致这种情况的原因吗?这是 .NET Core 3 预览版的错误吗?
在您的 AppState 中.cs您有 using 语句using System.Web.Helpers;
。System.Web
命名空间在 ASP.NET 中使用,并已被放弃用于 ASP.NET 核心。
我刚刚创建了一个新的 Blazor Wasm 项目(但这也可以使用 Blazor Serverside,不确定你使用的是哪个)并粘贴了你的AppState
类。找不到命名空间System.Web.Helpers
,类也无法LoginDetails
。你可能想要仔细检查所有引用和 NuGet 包,因为我非常确定有人添加了命名空间System.Web.Helpers
和引用System.Web
这在 .NET Core 上不可用。