我在这里发布帖子,因为经过数小时的调查后,我找到了自己的答案。希望这能帮助未来的其他人!
所以问题是,在构建包时未将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。还要在BackgroundProcess项目的属性下添加Application>Assembly name&Default namespace扩展名。
示例类:
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中的项目)>属性>构建事件>在后期构建事件命令行下添加:
xcopy /y /s "$(TargetPath)" "$(SolutionDir)UWP"
构建并部署解决方案,AppServiceBridgeSample.BackgroundProcess.exe文件应该存在于UWP项目根目录中(在文件资源管理器中可见)。
此外,在调查期间,我升级了Visual Studio 15 Enterprise Preview 3,如果您遇到其他错误,这可能也有所帮助。