我在这里发帖是因为经过几个小时的调查后我找到了自己的答案。希望这将在未来对其他人有所帮助!
所以问题是在构建包时,BackgroundProcess.exe 没有包含在项目中。在.csproj 文件中定义了要包含在项目中的文件。在您喜欢的文本编辑器中打开它(记得关闭 Visual Studio)
在定义资产的地方添加:
<ItemGroup>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
这样的:
<ItemGroup>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
<Content Include="AppServiceBridgeSample.BackgroundProcess.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
请注意,我已将 AppServiceBridgeSample.BackgroundProcces.exe 添加为文件的命名空间。我不知道这是否完全有必要,但这就是我修复它的方式。因此,要修复命名空间,您必须在所有类之前添加 AppServiceBridgeSample。并且还在 Application > Assembly name & Default namespace 下的 BackgroundProcess 项目的属性中添加扩展。
示例类:
namespace AppServiceBridgeSample.BackgroundProcess
{
class Program
{
....
}
}
还有.xaml 例子:
<Page
x:Class="AppServiceBridgeSample.UWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppServiceBridgeSample.UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="Main"
mc:Ignorable="d">
...
</Page>
这也不会自动修复我遇到的错误,您还必须添加一个 构建事件,右键单击 BackgroundProcess(VS 中的项目)> 属性 > 构建事件 > 在 Post-Build 下事件命令行添加:
xcopy /y /s "$(TargetPath)" "$(SolutionDir)UWP"
构建和部署解决方案,并且 AppServiceBridgeSample.BackgroundProcess.exe 文件应该存在于 UWP 项目根目录中(在文件资源管理器中可见)。
此外,我在本次调查期间更新到 Visual Studio 15 Enterprise Preview 3,如果您遇到其他错误,这可能也会有所帮助。