C# 应用程序手动启动,但在安装后不会自动启动

C# 应用程序手动启动,但在安装后不会自动启动,c#,visual-studio,C#,Visual Studio,我正在Visual Studio 2015中编写一个程序。当我使用安装向导进行构建和安装,然后找到已安装的应用程序并双击它时,我没有发现任何问题。该应用程序将打开并完全可用 最近,我尝试在我的应用程序中添加一个“安装后自动启动”:它成功构建并安装,但不运行。相反,我在事件查看器中得到以下错误: Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.Direc

我正在Visual Studio 2015中编写一个程序。当我使用安装向导进行构建和安装,然后找到已安装的应用程序并双击它时,我没有发现任何问题。该应用程序将打开并完全可用

最近,我尝试在我的应用程序中添加一个“安装后自动启动”:它成功构建并安装,但不运行。相反,我在事件查看器中得到以下错误:

Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
   at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare)
   at System.Drawing.Icon..ctor(System.String, Int32, Int32)
   at System.Drawing.Icon..ctor(System.String)
   at myApp.Form1.buildIconArray(System.String)
   at myApp.Form1..ctor()
   at myApp.Program.Main()
这是buildIconArray

public void buildIconArray(string name)
        {
            for (int i = 0; i <= 100; i++)
            {
                iconArray[i] = new Icon("icons/" + name + "/" + i + ".ico");
            }
        }
就像我说的,即使使用这个修改脚本进行安装,我也能够正常地打开和操作程序,而且不会出错

看起来问题可能出在systemio上?当我删除此功能时,应用程序不会出错,但也不会生成任何图标..:/


我没有使用OneClick安装程序,无法确定如何使其在VS2015中工作。如果有人能给我指出正确的方向,我愿意试一试。我在使用这个:

感谢布伦丹·格林在评论中的评论


问题是应用程序是安装的。应用程序是从安装程序目录运行的,而不是从安装目录运行的。

您正在执行OneClick发布,对吗?图标存储在哪里以及它们在做什么?不,找不到。使用:猜一猜-我会说启动时您的工作目录是安装程序完成后的ng与双击应用程序时的工作目录不同。因此图标路径与当前工作目录相对,并且看起来不存在。如果
图标
文件夹位于应用程序的安装目录下,请更改生成的路径,以包括e应用程序的完整路径。谢谢Brendan,就是这样。刚刚开始使用application.StartupPath使用绝对路径
Icon[] iconArray = new Icon[101];