小编Alp*_*a75的帖子

在 Nuget 中为 PackageReferece 项目打包静态内容

我有一个类库 (net47) 项目,我想将我的 dll 和几个静态内容文件(js、css、图像...)打包到一个 nuget 中。我想使用这个 dll 和来自消费者项目的内容。这些项目将是 MVC PackageReference 项目。在这些项目中,本地静态文件位于 wwwroot 文件夹中。

我试过这个:NuGet ContentFiles Demystified但我引用了我的 js 和 css 文件(它们没有复制到我的项目内容中)。

在我的 nuspec 中,我尝试了所有构建选项:EmbeddedResource、Content、None 和 Compile,但这些引用始终以编译模式导入。所以当我开始调试时出现编译错误。

我知道这可以通过 Package.config 项目实现,而且非常简单,但我所有的消费者项目都是 PackageReference。

这是我的 nuspec

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>MyProject</id>
    <version>1.0.0</version>
    <authors>My</authors>
    <owners>My</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>LVP</description>
    <copyright>Copyright 2018</copyright>
    <tags>Tag1 Tag2</tags>
    <contentFiles>
        <files include="any/any/bd.js" buildAction="content" flatten="true" copyToOutput="false"/>
    </contentFiles>
  </metadata>
  <files>
    <file src="contentFiles/any/any/bd.js" target="contentFiles/any/any/bd.js" />
  </files>
</package>
Run Code Online (Sandbox Code Playgroud)

我用这个 powershell 命令打包我的 nuget:

nuget pack MyProject.nuspec
Run Code Online (Sandbox Code Playgroud)

虽然我也尝试过 csproj:

nuget pack MyProject.csproj
Run Code Online (Sandbox Code Playgroud)

我的源文件夹结构是这样的:

C:\...[projectPath]...\contentFiles\any\any\bd.js
Run Code Online (Sandbox Code Playgroud)

安装忽略了我的构建操作。为什么总是试图编译我的内容文件?有没有更好的方法将静态内容添加到消费者项目中?

static-content nuget nuspec

7
推荐指数
1
解决办法
5328
查看次数

当我在 ServiceFabric 集群上使用 EventFlow 侦听 ETW 事件时,出现“系统资源不足”的情况

我有一个使用在 Service Fabric 上运行的 EventFlow 的 ETW 侦听器。

这是我的配置文件(eventFlowConfig.json):

{
  "inputs": [
    {
      "type": "ETW",
      "sessionNamePrefix": "MyListenerService",
      "cleanupOldSessions": true,
      "reuseExistingSession": true,
      "providers": [
        {
          "providerName": "Provider0"
        }
      ]
    }
  ],
  "filters": [],
  "outputs": [
    {
      "type": "CustomOutput"
    }
  ],
  "schemaVersion": "2018-04-04",

  "extensions": [
    {
      "category": "outputFactory",
      "type": "CustomOutput",
      "qualifiedTypeName": "MyNamespace.EventFlow.Outputs.CustomOutputFactory, MyAssembly"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

这是我的切入点:

private static void Main()
{
    try
    {
        string configurationFileName = "eventFlowConfig.json";

        using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("MyService", configurationFileName))
        {
            ServiceRuntime.RegisterServiceAsync("MyServiceType",
                context => new Service(context)).GetAwaiter().GetResult();

            ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name); …
Run Code Online (Sandbox Code Playgroud)

c# etw event-flow azure-service-fabric asp.net-core

4
推荐指数
1
解决办法
4433
查看次数

排除迁移的属性

我的模型上有一些属性,我不想在迁移后在表中生成字段。

是否可以排除Entity Framework Core 迁移的属性

我的模型是否有一个属性或一些 Fluent API 方法DbContext

.net c# entity-framework-core .net-core entity-framework-migrations

4
推荐指数
1
解决办法
5904
查看次数

来自 NServiceBus Behavior 的范围依赖使用

我正在尝试使用Scoped来自 NServiceBus的依赖项Behavior

来自NServiceBus 行为文档:

行为仅创建一次,并且在每次调用管道时都会重用相同的实例。因此,即使在依赖注入中注册时指定了不同的选项,每个行为依赖也将表现为单例。此外,在调用阶段调用的行为和所有依赖项需要是并发安全的并且可能是无状态的。应该避免在行为实例中存储状态,因为它会导致在所有消息处理会话中共享状态。这可能会导致不必要的副作用。

由于 aBehavior是单例并且 the 的Invoke方法Behavior不允许注入任何依赖项(例如invokenet core 中间件的方法,因为在这种情况下它是常规接口实现),因此我不能scoped从这里使用依赖项。

我试图Invoke通过在构造函数中传递 IServiceCollection来解决我的方法中每个传入/传出消息的依赖项:

private readonly IServiceCollection _services;

public MyIncomingMessageBehavior(IServiceCollection services)
{
    _services = services;
}

public override async Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next)
{
    var myScopedDependency = _services.BuildServiceProvider().GetService<IMyScopedDependency>();
    // always 
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用

那是因为当您将 IServiceProvider 注入中间件时 - 那是“全局”提供者,而不是请求范围的。调用中间件构造函数时没有请求(中间件在启动时创建一次),因此它不能是请求范围的容器。

总之,我的作用域依赖包含当前上下文的数据,我想从Invoke我的Behavior单例方法访问这些数据?

有什么办法吗?

.net dependency-injection nservicebus asp.net-core

3
推荐指数
1
解决办法
327
查看次数

从 DocumentDB 联接查询中获取所有字段

我在 Azure 中有一个 DocumentDB 数据库,我通过 CosmosDB API 访问它。

我想通过一个简单的查询获取文档的所有父字段:

SELECT p.id 
    FROM parent p JOIN ch IN p.property1.child
    WHERE CONTAINS(UPPER(ch.name), UPPER(@childName))
Run Code Online (Sandbox Code Playgroud)

这个查询有效,但我只得到 'id' 属性。我不能使用 p.* (抛出一个语法错误),而且这个列表将来可能会改变。使用 * 我收到此错误:'SELECT *' 仅对单个输入集有效。

有没有一种方法可以获取父文档的整个 json,而无需在 select 子句上编写完整的字段列表?

nosql document-database azure-cosmosdb

2
推荐指数
1
解决办法
597
查看次数