我有一个包含 ASP .NET Core 的 Windows 服务应用程序
project.json 有 2 个命令:
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"service": "MyAppNamespace"
}
入口点类:
public class Program : ServiceBase
{
IApplication _application;
public Program(IServiceProvider serviceProvider)
{
}
public void Main(string[] args)
{
Run(this);
}
protected override void OnStart(string[] args)
{
var configProvider = new MemoryConfigurationProvider();
configProvider.Add("server.urls", "http://*:80");
var config = new ConfigurationBuilder()
.Add(configProvider)
.AddEnvironmentVariables()
.Build();
_application = new WebHostBuilder(config)
.UseServer("Microsoft.AspNet.Server.Kestrel")
.UseStartup<Startup>()
.Build()
.Start();
// my stuff bellow
}
protected override void OnStop()
{
_application?.Dispose();
}
}
发布项目后,我们有这个文件夹结构:
approot
logs
wwwroot
接下来我从控制台启动我的应用程序
dnx.exe -p "C:\MyProject\approot\src\MyProject" service
但是我们没有使用“C:\MyProject\wwwroot”中的 webroot 目录,而是与 project.json 相同,即“C:\MyProject\approot\src\MyProject”
如果我通过这样的“web”命令启动应用程序:
dnx.exe -p "C:\MyProject\approot\src\MyProject" web
然后一切正常,但当然我的入口点被忽略了,我无法执行我的东西,也不能作为服务运行
项目.json
{
"version": "1.0.0-*",
"dependencies": {
"MicroORM": "1.0.7",
"Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1",
"Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
"Npgsql": "3.0.5",
"ObjectPool": "1.0.0"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:80",
"service": "MikroBill"
},
"frameworks": {
"dnx46": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.ServiceProcess": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}