Blazor .NET Core 3预览版编译错误-Visual Studio 2019预览版

时间:2019-08-25 23:29:01

标签: c# visual-studio-2019 blazor .net-core-3.0

我目前无法使用.NET Core 3 Preview和Visual Studio 2019 Preview(最新版本,刚刚下载)来编译Blazor应用程序

我只创建了几个文件。

MainLayoutModel.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();
        }
    }
}

LoginDetails.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(项目根目录)

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:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor.mono\3.0.0-preview8.19380.1\build\netstandard1.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:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor.mono\3.0.0-preview8.19380.1\build\netstandard1.0\../../tools/mono/bcl/" -d "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor.mono\3.0.0-preview8.19380.1\build\netstandard1.0\../../tools/mono/bcl/Facades/" -o "C:\Users\adamc\Desktop\ICSSNetworkManager\ICSSNetwork\ICSSNetwork\obj\Debug\netstandard2.0\blazor\linker/" -x "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor.build\3.0.0-preview8.19405.7\targets\BuiltInBclLinkerDescriptor.xml" -x "C:\Users\adamc\Desktop\ICSSNetworkManager\ICSSNetwork\ICSSNetwork\obj\Debug\netstandard2.0\blazor\linker.descriptor.xml" -a "C:\Users\adamc\.nuget\packages\blazored.localstorage\2.0.12\lib\netstandard2.0\Blazored.LocalStorage.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnet.razor\3.2.7\lib\net45\System.Web.Razor.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnet.webpages\3.2.7\lib\net45\System.Web.Helpers.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnet.webpages\3.2.7\lib\net45\System.Web.WebPages.Deployment.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnet.webpages\3.2.7\lib\net45\System.Web.WebPages.Razor.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnet.webpages\3.2.7\lib\net45\System.Web.WebPages.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.authorization\3.0.0-preview8.19405.7\lib\netstandard2.0\Microsoft.AspNetCore.Authorization.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor\3.0.0-preview8.19405.7\lib\netstandard2.0\Microsoft.AspNetCore.Blazor.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor.httpclient\3.0.0-preview8.19405.7\lib\netstandard2.0\Microsoft.AspNetCore.Blazor.HttpClient.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.components\3.0.0-preview8.19405.7\lib\netstandard2.0\Microsoft.AspNetCore.Components.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.components.web\3.0.0-preview8.19405.7\lib\netstandard2.0\Microsoft.AspNetCore.Components.Web.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.metadata\3.0.0-preview8.19405.7\lib\netstandard2.0\Microsoft.AspNetCore.Metadata.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.bcl.asyncinterfaces\1.0.0-preview8.19405.3\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.extensions.dependencyinjection\3.0.0-preview8.19405.4\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\3.0.0-preview8.19405.4\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.extensions.logging.abstractions\3.0.0-preview8.19405.4\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.extensions.options\3.0.0-preview8.19405.4\lib\netstandard2.0\Microsoft.Extensions.Options.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.extensions.primitives\3.0.0-preview8.19405.4\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.jsinterop\3.0.0-preview8.19405.4\lib\netstandard2.0\Microsoft.JSInterop.dll" -a "C:\Users\adamc\.nuget\packages\microsoft.web.infrastructure\1.0.0\lib\net40\Microsoft.Web.Infrastructure.dll" -a "C:\Users\adamc\.nuget\packages\mono.webassembly.interop\3.0.0-preview8.19405.4\lib\netstandard2.0\Mono.WebAssembly.Interop.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.buffers\4.5.0\lib\netstandard2.0\System.Buffers.dll" -a "C:\Users\adamc\.nuget\packages\system.componentmodel.annotations\4.6.0-preview8.19405.3\lib\netstandard2.0\System.ComponentModel.Annotations.dll" -a "C:\Users\adamc\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.numerics.vectors\4.5.0\lib\netstandard2.0\System.Numerics.Vectors.dll" -a "C:\Users\adamc\.nuget\packages\system.runtime.compilerservices.unsafe\4.6.0-preview8.19405.3\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll" -a "C:\Users\adamc\.nuget\packages\system.text.encodings.web\4.6.0-preview8.19405.3\lib\netstandard2.0\System.Text.Encodings.Web.dll" -a "C:\Users\adamc\.nuget\packages\system.text.json\4.6.0-preview8.19405.3\lib\netstandard2.0\System.Text.Json.dll" -a "C:\Users\adamc\.nuget\packages\system.threading.tasks.extensions\4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll" -a "C:\Users\adamc\Desktop\ICSSNetworkManager\ICSSNetwork\ICSSNetwork\obj\Debug\netstandard2.0\ICSSNetwork.dll"" exited with code -532462766. ICSSNetwork C:\Users\adamc\.nuget\packages\microsoft.aspnetcore.blazor.build\3.0.0-preview8.19405.7\targets\Blazor.MonoRuntime.targets 441

任何人都不知道这可能是什么原因? .NET Core 3预览版是否有错误?

1 个答案:

答案 0 :(得分:1)

在AppState.cs中,您具有using语句using System.Web.Helpers;System.Web命名空间已在ASP.NET中使用,已被ASP.NET Core放弃。

我刚刚创建了一个新的Blazor Wasm项目(但是也可以使用Blazor Serverside,但不确定使用的是哪个项目),并粘贴了AppState类。找不到命名空间System.Web.Helpers,也找不到类LoginDetails。您可能需要仔细检查所有引用和NuGet软件包,因为我非常确定一个添加了命名空间System.Web.Helpers和引用System.Web,而这些命名空间在.NET Core中不可用。