我听说.NET Core也可以在Linux和Mac上运行.我目前在Raspberry PI上使用Mono.是否可以或者可以在Raspberry PI上运行.NET Core?
如何在asp.net核心中获取resx文件字符串?我在mvc中使用ResxResourceReader获取字符串.但是我无法在asp.net核心中获得相同的功能.
我正在运行 Visual Studio 2017 15.9。程序已成功构建,但每次我右键单击“调试测试”时,编译器都会退出并显示以下消息:
程序“[xxxxx] testhost.x86.exe”已退出,代码为 0 (0x0)
调试输出屏幕和测试输出屏幕均显示该消息
VirtualReadOnlyTestDataStore.OperationStateChanged 状态=TestExecutionFinished,操作InProgress=False TestDiscoveryStats.OperationStateChanged 状态=TestExecutionFinished,InProgress=False
即使放入函数断点后也会出现此消息。编译器不会命中断点,并且会以相同的消息退出。代码似乎没有任何问题,因为它在我同事的笔记本电脑上运行良好。此外,测试资源管理器中的所有测试都没有显示绿色勾号,它们都有蓝色感叹号
我尝试将测试设置>默认处理器架构更改为x64(我的计算机是64位)。我已经将 VS 更新到最新版本。甚至尝试重新安装 Visual Studio,但它再次显示相同的错误。
线程 0x5aa8 已退出,代码为 0 (0x0)。线程 0x166c 已退出,代码为 0 (0x0)。程序“[13392] testhost.exe”已退出,代码为 0 (0x0)。
我有很多项目的解决方案。一些目标框架netcoreapp2.1,一些其他目标框架netstandard2.0,一个项目有双目标框架
<TargetFrameworks>netstandard2.0;net471</TargetFrameworks>
Run Code Online (Sandbox Code Playgroud)
我想要一个用于 win10 的神器,只需一个命令:
dotnet publish MySolution.sln -c Release -o "targetFolder" -r win10-x64
Run Code Online (Sandbox Code Playgroud)
使用此命令,我在使用双目标框架构建项目时遇到此错误。这是错误:
C:\Program Files\dotnet\sdk\2.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CrossTargeting.targets(31,5) error : The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application.
Run Code Online (Sandbox Code Playgroud)
错误很明显。最后我发现 dll 在输出目录中编译,看起来它是一个 netstandard2.0 dll,因为我的应用程序仍然可以工作。
我不喜欢肮脏的东西,那么我该如何解决我的问题呢?
如果可能的话,我会避免调用 N 次“dotnetpublish”命令。
我有一些针对net标准2.0的项目和针对netcore 2.1的控制台应用程序的解决方案
我设置为输出文件夹“ myFolder”。从Visual Studio构建,我得到所有dll:
使用“ dotnet build”命令可以得到相同的结果。现在,我需要控制台应用程序的exe文件。所以我使用“ dotnet publish -c Release -r win-x64 MySolution.sln”命令。
现在,我得到了这个新目录“ myFolder \ netcoreapp2.1 \ win-x64”,在其中可以找到所有dll和控制台应用程序的exe文件。
不够!
我再找到一个目录:“ myFolder \ netcoreapp2.1 \ win-x64 \ publish”,在这里我再次找到所有dll和控制台应用程序的exe文件。
我不知道他们有什么意思。我阅读了命令文档,但没有找到答案。
有人照亮我吗?
我知道 .net core 已经用 appsetting.json 替换了 app.config 文件。然而,这个文件似乎只为 ASP.net 项目添加。事实上,它甚至在添加项目列表中都不可用。我发现这篇文章列出了需要添加的包:
- Microsoft.Extensions.Configuration
- Microsoft.Extensions.Configuration.FileExtensions
- Microsoft.Extensions.Configuration.Json
我添加了所有这些,它确实给了我添加 json 配置文件的选项,但仍然不是App Settings File仅在 ASP.Net Core 下可用的选项。我试图了解为什么非 Web 项目不需要配置以及配置 .net 核心控制台应用程序的推荐方法是什么。提前致谢。
我正在为 Windows 构建一个应用程序,我需要通过串行端口传输数据,但我不知道如何使它工作。我尝试了不同的声明,不同的imports,但没有。以下是我从图片中看到的 3 种方法中得到的 3 个错误:
'SerialPort1' 未声明。由于保护级别,它可能无法访问。\ 'SerialPorts' 未声明。由于保护级别,它可能无法访问。\“Ports”不是“MyComputer”的成员。
此外,它不会将其作为错误发出信号,但我System.IO.Ports在“nuGet 包”文件夹中找不到,并且无法安装它(其先决条件也无法安装)
我有最新版本的 .NET 框架:5.0.100
感谢任何可以提供帮助的人!
使用的进口:
Imports System.Windows.Forms
Imports System
Imports System.IO.Ports
Run Code Online (Sandbox Code Playgroud)
这个子在实际程序中处于公共类中
SubGetSerialPortNames()显示所有可用的 COM 端口。获取串行端口名称列表。
SerialPort1.Open() 'first way i tried
Dim ports As String() = SerialPorts.GetPortNames() 'second way i tried
' Show all available COM ports. third way i tried
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox_Serial_Ports.Items.Add(sp)
Next
End Sub
Run Code Online (Sandbox Code Playgroud) 我在 .NET Core 3.0 上使用 Blazor Preview 9 服务器端以及用于在浏览器的本地存储中加载和保存数据的 nuget 包 Blazored.LocalStorage。
现在我想在加载应用程序时在需要时加载它一次。
为此,我需要使用 OnFirstRenderer,因为它必须完全位于客户端才能访问它的浏览器缓存。现在我使用页面“/”(Index.razor),但我不太确定这是否是正确的锚点或执行此操作的方法:
[Parameter]
public string Test { get; set; }
protected async override Task OnAfterRenderAsync(bool firstRender)
{
try
{
if (firstRender)
{
await localStorage.SetItemAsync("TEST", "Hallo Welt");
}
if (Test == null)
{
Test = await localStorage.GetItemAsync<string>("TEST");
StateHasChanged();
}
}
catch (Exception ex)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
此外,我不知道如何使其适用于所有组件:
使用全局变量创建服务并将其注入每个组件或通过 CascadingValue 方法执行它是最好的方法吗?
谢谢!
我正在编写一个应用程序 ASP.Net Core (2.2) MVC。我需要根据登录用户的某些声明的值过滤 DbContext 内的一些数据。我注入 IHttpContextAccessor,但是当我尝试访问 HttpContext.User.Identity 时 - 所有属性均为 null,所有声明均为空。
这就是我试图实现连接 IHttpContextAccessor 的方式。我使用这样的标准方法:
public void ConfigureServices(IServiceCollection services){
services.AddHttpContextAccessor();
...
}
Run Code Online (Sandbox Code Playgroud)
然后我构建一个自定义提供程序来从用户中提取声明:
public class GetClaimsFromUser : IGetClaimsProvider
{
public string UserId {get; private set;}
public GetClaimsFromUser(IHttpContextAccessor accessor)
{
UserId = accessor.HttpContext?.User.Claims.SingleOrDefault(x => x.Type == ClaimTypes.Name)?.Value;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我还将它注入到ConfigureServices方法中:
public void ConfigureServices(IServiceCollection services){
...
services.AddScoped<IGetClaimsProvider, GetClaimsFromUser>();
...
}
Run Code Online (Sandbox Code Playgroud)
之后,我将其注入到 ApplicationDbContext 中,并尝试在构造函数中设置私有 _userId 字段:
public class ExpenseManagerDbContext: IdentityDbContext<ApplicationUser>
{
private string _userId;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IGetClaimsProvider claimsProvider) : base(options)
{ …Run Code Online (Sandbox Code Playgroud) .net-core ×6
asp.net-core ×3
c# ×3
.net ×2
basic ×1
blazor ×1
build ×1
deployment ×1
dotnet-cli ×1
raspberry-pi ×1
serial-port ×1
storage ×1
unit-testing ×1