小编Kla*_*msi的帖子

添加 .resx 文件时使用 WPF .net Core 3.0 编译错误

以下按预期工作: VS Studio 2019 经过专业人士和社区的测试。

  • 创建新的 APF 应用程序 (.NET Framework)
  • 打开属性文件夹
  • 将 Resources.resx 更改为 public
  • 创建一个新的资源文件 (Resources.de.resx)
  • 建造

按预期编译

以下不起作用:

  • 创建新的 APF 应用程序 (.NET Core)
  • 创建资源文件夹
  • 创建一个新的资源文件 (Resources.resx)
  • 改成公开的
  • 创建一个新的资源文件 (Resources.de.resx)
  • 建造

使用 VS 2019 专业版和社区在 3 台不同的机器上对其进行了测试

编译错误:

错误自定义工具 PublicResXFileCodeGenerator 未能为输入文件“Resources\Resources.de.resx”生成输出,但未记录特定错误。WpfApp4 C:...\source\repos\WpfApp4\WpfApp4\Resources\Resources.de.resx 1

错误 MSB3086 任务无法使用 SdkToolsPath“”或注册表项“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\NETFXSDK\4.7.2\WinSDK-NetFx40Tools-x86”找到“al.exe”。确保设置了 SdkToolsPath 并且该工具存在于 SdkToolsPath 下正确的处理器特定位置,并且安装了 Microsoft Windows SDK WpfApp4 C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin \Microsoft.Common.CurrentVersion.targets 3639

编辑:还在微软创建了一张票

https://developercommunity.visualstudio.com/content/problem/771961/compile-error-with-wpf-net-core-30-when-adding-res.html

c# wpf localization resx .net-core

5
推荐指数
1
解决办法
1753
查看次数

在 IServiceCollection.AddLogging (C#/.net Core) 中获取服务

在我的 .net Core C# 应用程序(不是 ASP)中,我构建了一个类来处理我的服务。你必须像这样配置它

MyBaseClass.BuildServiceProvider(serviceCollection =>
                serviceCollection
                    .AddMyConfiguration(out var config)
                    .AddMyEMailService()
                    .AddMyLoggingService(config)
            );
Run Code Online (Sandbox Code Playgroud)

问题是AddMyLoggingService,因为我不知道如何获取其他服务。我已经传入了配置,我认为这不是 DI 想要的,现在我还必须传入电子邮件服务。

日志服务看起来像这样

public static class ServiceCollectionHelper
    {
        public static IServiceCollection AddMyLoggingService(this IServiceCollection coll, IConfiguration config)
        {
            coll.AddLogging(builder =>
                builder
                    .AddConfiguration(config)
                    .AddDebug()
                    .AddEventLog()
                    .AddProvider(new MyTicketLoggerProvider(config))
            );

            return coll;
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在 MyTicketLoggerProvider 需要注入 .AddMyEMailService 的电子邮件服务来创建票证(通过向票证系统发送电子邮件)

我不知道什么是最佳实践。

[编辑] 一种解决方法是我在 AddMyLoggingService 中创建一个临时提供程序

var tmpProvider = coll.BuildServiceProvider();
Run Code Online (Sandbox Code Playgroud)

能够访问服务

c# service dependency-injection core

5
推荐指数
0
解决办法
458
查看次数

标签 统计

c# ×2

.net-core ×1

core ×1

dependency-injection ×1

localization ×1

resx ×1

service ×1

wpf ×1