在 Visual Studio 2017 中为 WPF 应用程序创建 MSI 安装程序后,EXE 什么也不做 [英] After creating MSI Installer for WPF app in Visual Studio 2017, EXE does nothing

查看:23
本文介绍了在 Visual Studio 2017 中为 WPF 应用程序创建 MSI 安装程序后,EXE 什么也不做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 中为控制台应用程序使用了安装项目,没有任何问题,但是,到目前为止,我一直在运行我在 Visual Studio 中创建的任何 WPF 应用程序.这是我第一次尝试出版.我觉得如果我只知道如何处理我的子文件夹,这将非常简单.我有许多用于按钮的图像、用于徽标的 PNG 和两个 PowerShell 脚本.

I've used the Setup Project in Visual Studio for Console apps with no problems, however, until now, I've always ran any WPF apps I've created in Visual Studio. This is my first attempt at publishing one. I feel this would be pretty simple if I only knew what to do with my subfolders. I have many images that I use for buttons, a PNG for a logo, and two PowerShell scripts.

我需要选择的不仅仅是主要输出吗?

Do I need to select more than just the Primary output?

以下是数据的用法,供参考:

Here is the usage of the data for reference:

PowerShell 脚本(仅显示相关代码):

The PowerShell Scripts (just showing relevant code):

 private static string checkAppsScript = File.ReadAllText(@"scripts\checkApps.ps1");
 private static string removeAllScript = File.ReadAllText(@"scripts\removeall.ps1");

 PowerShell removePS = PowerShell.Create();
 removePS.AddScript(removeAllScript);

 PowerShell ps = PowerShell.Create();
 ps.AddScript(checkAppsScript);

来自我的 XAML 数据文件夹中的图像(有 18 个.仅显示 1 个):

The images from the data folder from my XAML (There are 18. Just showing 1):

<StackPanel Grid.Row="0" Grid.Column="0">
    <Button Name="bingweatherBtn" Margin="10" Style="{StaticResource ImageButtonStyle}" Click="ImageBtn_Click">
        <Button.BitmapEffect>
            <DropShadowBitmapEffect Color="Black" Direction="320" Opacity="0.8"/>
        </Button.BitmapEffect>
            <Border BorderBrush="Black" BorderThickness="2">
                <Image Source="data\weather_icon80x80.jpg"></Image>
            </Border>
        </Button>
        <Label Content="Bing Weather" FontSize="14" FontWeight="SemiBold" Padding="0" HorizontalAlignment="Center"></Label>
</StackPanel>

我设法找到的所有教程都显示了简单的控制台应用程序或没有其他文件夹的简单 WPF 应用程序.创建我的 .msi 文件后,可执行文件什么也不做.它显示一个忙碌的动画大约一秒钟然后退出.

Any tutorials I've managed to find all show simple Console apps or simple WPF apps without additional folders. After creating my .msi file, the executable does nothing. It shows a busy animation for about a second and quits.

我在这里做错了什么?为什么我的应用只能在 Visual Studio 中运行?

What am I doing wrong here? Why does my app only run in Visual Studio?

注意:数据和资源文件夹中的所有内容都设置为构建操作"的内容,PS 脚本设置为嵌入式资源.我不知道这是否正确.目标平台设置为 x64.

Note: Everything in the data and Resources folder is set as Content for the 'Build Action', and the PS scripts are set as Embedded Resource. I don't know if this is correct. Target platform is set to x64.

推荐答案

我删除了脚本并将它们硬编码到 MainWindow.xaml.cs 文件中,如下所示:

I removed the scripts and hard coded them into the MainWindow.xaml.cs file like so:

private static string checkAppsScript = @"$appList = @('*BingNews*','*BingWeather*','*OneNote*','*WindowsAlarms*', 
                                                           '*Recorder*', '*Maps*','*Camera*', '*Microsoft.People*',
                                                           '*xboxapp*', 'ZuneMusic*','*Messaging*', '*Builder*', 
                                                           '*BubbleWitch*', '*Minecraft*', '*Spotify*',
                                                           '*Empires*', '*StickyNotes*', '*Skype*', '*SolitaireCollection*')


                                            ForEach($app in $appList)
                                            {
                                              Get-AppxPackage | Select Name | Where-Object {$_.Name -like $app}
                                            }";

我删除了图像并使用添加现有项目"重新添加了它们.我最初使用的是添加项目".我将所有图像放在一个 res 文件夹中(我有两个文件夹,这是毫无意义的).可执行文件现在可以工作了.

I removed the images and re-added them using "Add Existing Item." I had originally used "Add Item." I placed all images in a res folder (I had two folders, which was pointless). The executable now works.

这篇关于在 Visual Studio 2017 中为 WPF 应用程序创建 MSI 安装程序后,EXE 什么也不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆