我正在尝试使用存储在 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) 如何在 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) 我正在尝试使用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约束类型?
我正在尝试使用 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)