小编Ben*_*min的帖子

如何使用模板引用 Azure DevOps Pipelines 中另一个存储库中的脚本?

我正在尝试使用存储在 Azure DevOps 中另一个 Git 存储库中的模板,其中该模板引用了也包含在该存储库中的脚本。虽然我可以成功使用主管道中的模板,但它没有引用模板所需的脚本。

请问我有什么办法可以做到这一点吗?

HelloWorld 模板/脚本存储在 Azure DevOps Repo“HelloWorld”中名为“Templates”的子文件夹中。

HelloWorld.ps1 脚本与以下模板位于同一目录中。

param($Name)

Write-Host "Hello, $Name!"
Run Code Online (Sandbox Code Playgroud)

模板 #1 参考本地脚本

param($Name)

Write-Host "Hello, $Name!"
Run Code Online (Sandbox Code Playgroud)

模板#2

  parameters:
  - name: azureSubscription
    type: string
  - name: name
    type: string
  
  jobs:
  - job: HelloWorld
    displayName: Hello World
    variables:
      name: ${{ parameters.name }}
    steps:
    - task: AzurePowerShell@4
      name: HelloWorld
      displayName: Hello World
      inputs:
        azureSubscription: ${{ parameters.azureSubscription }}
        scriptType: filePath
        scriptPath: ./HelloWorld.ps1
        azurePowerShellVersion: latestVersion
        failOnStandardError: true
        scriptArguments:
          -Name "$(name)"
Run Code Online (Sandbox Code Playgroud)

azure azure-devops azure-pipelines

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

如何将 LinkGenerator 添加到 ASP.NET Core?

如何在 Startup.cs方法中将LinkGenerator对象添加到我的for DI ?IServiceCollectionConfigureServices

public MyService(LinkGenerator linkGenerator) { }
Run Code Online (Sandbox Code Playgroud)

试过:

public static void AddLinkGenerator(this IServiceCollection services)
{
    services.AddHttpContextAccessor();
    services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
    services.AddScoped<IUrlHelper, UrlHelper>(implementationFactory =>
    {
        var actionContext = implementationFactory.GetService<IActionContextAccessor>().ActionContext;
        return new UrlHelper(actionContext);
    });
}
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection asp.net-core

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

C#8.0 notnull通用类型约束

我正在尝试使用VS2019 Preview 16.4.0中刚刚发布的.NET Standard 2.1 C#8.0功能,但始终收到消息``无法解析符号'notnull'''。

我的示例代码:

class Example<T> where T : notnull {}
Run Code Online (Sandbox Code Playgroud)

我在项目文件中设置了<Nullable>enable</Nullable><LangVersion>8</LangVersion>属性,所有这些新功能都很好用,似乎就是这样。

如何使用notnull约束类型?

c# c#-8.0

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

如何使用 Moq 在 .NET Core 3.1 中对 LoggerMessage.Define() 进行单元测试?

我正在尝试使用 xUnit 中的 Moq 库对 LoggerMessage.Define() 的一些用法进行单元测试,但无法弄清楚。下面是我创建的日志记录函数的示例,下面是一个示例单元测试,无法检查它是否被调用。

LoggerMessage.Define() 示例:

public static class GlobalExceptionLoggerMessage
{
    public static Action<ILogger, string, Exception> GlobalException = LoggerMessage.Define<string>(
        LogLevel.Error,
        new EventId(StatusCodes.Status500InternalServerError, nameof(GlobalException)),
        "{Message}");

    public static void LogGlobalException(this ILogger logger, string message, Exception exception)
    {
        GlobalException(logger, message, exception);
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试过的单元测试示例:

[Fact]
public void LogGlobalExceptionLogTest()
{
    var loggerMock = new Mock<ILogger<object>>();

    var exception = new Exception("Person must exist.");
    const string message = "Person must exist for an object.";

    loggerMock.Object.LogGlobalException(message, exception);

    loggerMock.Verify(
        x => x.Log(
            It.IsAny<LogLevel>(),
            It.IsAny<EventId>(),
            It.Is<It.IsAnyType>((v, …
Run Code Online (Sandbox Code Playgroud)

c# moq xunit .net-core

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