using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
{
return args =>
{
+ static bool IsApplicationNameArg(string arg)
+ => arg.Equals("--applicationName", StringComparison.OrdinalIgnoreCase) ||
+ arg.Equals("/applicationName", StringComparison.OrdinalIgnoreCase);
+
+ args = args.Any(arg => IsApplicationNameArg(arg)) || assembly.FullName is null
+ ? args
+ : args.Concat(new[] { "--applicationName", assembly.FullName }).ToArray();
+
var host = hostFactory(args);
return GetServiceProvider(host);
};
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFrameworks>$(NetCoreAppCurrent);net461</TargetFrameworks>
+ <EnableDefaultItems>true</EnableDefaultItems>
+ <OutputType>Exe</OutputType>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\MockHostTypes\MockHostTypes.csproj" />
+ </ItemGroup>
+
+</Project>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+
+var host = new HostBuilder().ConfigureAppConfiguration(builder => builder.AddCommandLine(args)).Build();
\ No newline at end of file
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using Microsoft.Extensions.Configuration;
using MockHostTypes;
using System;
using System.Diagnostics.CodeAnalysis;
Assert.IsAssignableFrom<IServiceProvider>(factory(Array.Empty<string>()));
}
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+ public void ApplicationNameSetFromAgrument()
+ {
+ Assembly assembly = Assembly.Load("ApplicationNameSetFromAgrument");
+ var factory = HostFactoryResolver.ResolveServiceProviderFactory(assembly, s_WaitTimeout);
+ IServiceProvider? serviceProvider = factory(Array.Empty<string>());
+
+ var configuration = (IConfiguration)serviceProvider.GetService(typeof(IConfiguration));
+ Assert.Contains("ApplicationNameSetFromAgrument", configuration["applicationName"]);
+ }
+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
public void NoSpecialEntryPointPatternCanRunInParallel()
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="ApplicationNameSetFromAgrument\ApplicationNameSetFromAgrument.csproj" />
<ProjectReference Include="BuildWebHostInvalidSignature\BuildWebHostInvalidSignature.csproj" />
<ProjectReference Include="BuildWebHostPatternTestSite\BuildWebHostPatternTestSite.csproj" />
<ProjectReference Include="CreateHostBuilderInvalidSignature\CreateHostBuilderInvalidSignature.csproj" />