我的文件结构就像
MyMVCProject
MyWindowsService
bin
obj
.
.
MyMVCProject
App_Data
App_Start
bin
.
.
packages
MyMVCProject.sln
和MyWindowsService
依赖于MyMVCProject
因为我希望当我的MVC应用程序开始运行时,它有一个后台进程来连接我在MVP项目中定义的存储库和数据上下文。
我建立MyWindowsService
时会自行安装,因为我放了
cd C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 installutil.exe" $(SolutionDir)\ MyWindowsService \ bin \ $(ConfigurationName)\ MyWindowsService.exe"
在该项目的post-build命令行中。它似乎在我自己构建该项目时起作用,因为我得到了像
这样的输出1>
1> Beginning the Install phase of the installation.
1> See the contents of the log file for the C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe assembly's progress.
1> The file is located at C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.InstallLog.
1> Installing assembly 'C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe'.
1> Affected parameters are:
1> logtoconsole =
1> logfile = C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.InstallLog
1> assemblypath = C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe
1> No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe assembly.
1>
1> The Install phase completed successfully, and the Commit phase is beginning.
1> See the contents of the log file for the C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe assembly's progress.
1> The file is located at C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.InstallLog.
1> Committing assembly 'C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe'.
1> Affected parameters are:
1> logtoconsole =
1> logfile = C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.InstallLog
1> assemblypath = C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe
1> No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\me\Documents\Visual Studio 2013\Projects\MyMVCProject\MyWindowsService\bin\Debug\MyWindowsService.exe assembly.
1> Remove InstallState file because there are no installers.
1>
1> The Commit phase completed successfully.
1>
然后我尝试在我的MVC项目的App_Start
中启动服务,如
string serviceExecutablePath = Path.GetFullPath(
Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
@"..\MyWindowsService",
"bin",
isDebugMode ? "Debug" : "Release",
"MyWindowsService.exe"
)
);
Process.Start(serviceExecutablePath);
因此,如果我构建并运行或构建并调试整个解决方案,那么步骤应该像
(1)编译MVC项目 (2)编译Windows服务项目(因为它取决于(1)) (3)启动MVC应用程序,它在启动时启动(2)
中内置的服务但是,当我这样做时,我收到了错误
知道我做错了什么以及如何解决它?
答案 0 :(得分:1)
似乎您的服务未安装在服务器上。如果未安装该服务,最好的方法是创建命令行可执行文件(bat文件)并从那里安装并启动它。
然后执行该文件可以这样做:
addFavoriteEvent = new EventEmitter();
pushData(value) {
this.addFavoriteEvent.emit(value)
}
当然,您可以从您的应用程序进行安装和运行,但请记住它是一个Web应用程序,通常最好不要运行需要管理员权限的事情。