发布Windows服务时遇Error 116错误,求解决方案及操作验证
Alright, let's break down what's causing this Error 116 and how to fix it. The core issue here is that the GenerateApplicationManifest MSBuild task only accepts a single config file for its ConfigFile parameter—but your build is producing two: obj\Debug\WindowsService.csproj.WindowsService.exe.config and obj\Debug\WindowsDateService.exe.config. The task can't handle multiple inputs, so it throws that invalid parameter error.
Is Commenting Out the TransformXml ItemGroup a Valid Fix?
Short answer: Yes, it can work—but only if that TransformXml node is the reason duplicate .config files are being generated. These nodes are typically used to transform App.config content for different environments, but if they're misconfigured (e.g., running twice, outputting to conflicting paths), they'll create duplicate configs that trigger this error.
Before you comment it out though, double-check what that node does. If it's critical for environment-specific config transformations, commenting it will break that logic. Instead, adjust the node's settings:
- Verify the
Destinationproperty points to a unique path that doesn't overlap with the default generated .config file - Make sure the
TransformXmltask isn't being called multiple times across different build targets
Other Reliable Fixes
If commenting the node isn't ideal (or doesn't work), try these approaches:
- Clean your build directories: Manually delete everything in the
obj\Debug(or your target build folder) directory, then rebuild. Old leftover build artifacts often cause duplicate config files to be picked up. - Check for duplicate project configs: Open your .csproj file and search for multiple App.config-related ItemGroups, or duplicate
GenerateApplicationManifesttask configurations that might be pointing to different configs. - Unify your output assembly name: If your project has two service classes (WindowsService and WindowsDateService), this might be causing conflicting .config filenames. Head to your project properties > Output tab and set a single, unique assembly name.
- Fix the manifest generation config: Locate the
GenerateApplicationManifestsection in your .csproj and ensure it only references one config file, like this:<GenerateApplicationManifest ConfigFile="$(OutputPath)$(AssemblyName).exe.config" />
Start with cleaning the build directory first—it's a quick fix that resolves this issue more often than you might think. If that doesn't work, dig into the TransformXml node or project config duplicates to get to the root cause.
内容的提问来源于stack exchange,提问作者jay

