public Task <int> Main(string[] args) { if (args.Length < 1) { Console.WriteLine("{app} [arguments]"); return(Task.FromResult(-1)); } var name = args[0]; var programArgs = args.Skip(1).ToArray(); var assembly = Assembly.Load(new AssemblyName(name)); if (assembly == null) { return(Task.FromResult(-1)); } #if ASPNET50 string applicationBaseDirectory; if (PlatformHelper.IsMono) { applicationBaseDirectory = Environment.GetEnvironmentVariable("KRE_APPBASE"); if (string.IsNullOrEmpty(applicationBaseDirectory)) { applicationBaseDirectory = Directory.GetCurrentDirectory(); } } else { applicationBaseDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; } #else string applicationBaseDirectory = AppContext.BaseDirectory; #endif var framework = Environment.GetEnvironmentVariable("TARGET_FRAMEWORK") ?? Environment.GetEnvironmentVariable("KRE_FRAMEWORK"); var configuration = Environment.GetEnvironmentVariable("TARGET_CONFIGURATION") ?? Environment.GetEnvironmentVariable("KRE_CONFIGURATION") ?? "Debug"; // TODO: Support the highest installed version var targetFramework = FrameworkNameUtility.ParseFrameworkName(framework ?? "aspnet50"); var applicationEnvironment = new ApplicationEnvironment(applicationBaseDirectory, targetFramework, configuration, assembly: assembly); CallContextServiceLocator.Locator = new ServiceProviderLocator(); var serviceProvider = new ServiceProvider(); serviceProvider.Add(typeof(IAssemblyLoaderContainer), _container); serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), LoadContextAccessor.Instance); serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); serviceProvider.Add(typeof(IAssemblyNeutralInterfaceCache), _assemblyNeutralInterfaceCache, includeInManifest: false); CallContextServiceLocator.Locator.ServiceProvider = serviceProvider; return(EntryPointExecutor.Execute(assembly, programArgs, serviceProvider)); }
public Task <int> Main(string[] args) { if (args.Length < 1) { Console.WriteLine("{app} [arguments]"); return(Task.FromResult(-1)); } var name = args[0]; var programArgs = args.Skip(1).ToArray(); var assembly = Assembly.Load(new AssemblyName(name)); if (assembly == null) { return(Task.FromResult(-1)); } #if NET45 // REVIEW: Need a way to set the application base on mono string applicationBaseDirectory = PlatformHelper.IsMono ? Directory.GetCurrentDirectory() : AppDomain.CurrentDomain.SetupInformation.ApplicationBase; #else string applicationBaseDirectory = ApplicationContext.BaseDirectory; #endif var framework = Environment.GetEnvironmentVariable("TARGET_FRAMEWORK") ?? Environment.GetEnvironmentVariable("KRE_FRAMEWORK"); var configuration = Environment.GetEnvironmentVariable("TARGET_CONFIGURATION") ?? Environment.GetEnvironmentVariable("KRE_CONFIGURATION") ?? "Debug"; var targetFramework = FrameworkNameUtility.ParseFrameworkName(framework ?? (PlatformHelper.IsMono ? "net45" : "net451")); var applicationEnvironment = new ApplicationEnvironment(applicationBaseDirectory, targetFramework, configuration, assembly: assembly); CallContextServiceLocator.Locator = new ServiceProviderLocator(); var serviceProvider = new ServiceProvider(); serviceProvider.Add(typeof(IAssemblyLoaderContainer), _container); serviceProvider.Add(typeof(IAssemblyLoaderEngine), _loaderEngine); serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); CallContextServiceLocator.Locator.ServiceProvider = serviceProvider; return(EntryPointExecutor.Execute(assembly, programArgs, serviceProvider)); }