1

I am having some issues, and I am not sure if it's caused by Visual Studio, or something within the application.

I wrote a simple console application to stop and start services. When I go to debug/release the application, it's compiling the application into a .dll.

I followed some instructions I found while googling to get the .exe, but when I do that, my output folder with the dependence is massive compared to the script (60MB).

I have made console applications many times, and normally the .exe is stored in the debug/release folder and works without issue. I am not sure what is different this time.

All I want is a simple .exe

Output from the build:

1>------ Build started: Project: FixAnyConnect, Configuration: Debug Any CPU ------ 1>FixAnyConnect -> C:\Users\jeh\Desktop\Projects\FixAnyConnect\FixAnyConnect\bin\Debug\netcoreapp2.1\FixAnyConnect.dll ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Full Code:

using System;
using System.Diagnostics;
using System.ServiceProcess;


namespace FixAnyConnect
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] serviceList = { "Cisco AnyConnect Network Access Manager", "Cisco AnyConnect Network Access Manager Logon Module", "Cisco AnyConnect Secure Mobility Agent" };
            //string[] serviceList = { "Print Spooler", "Realtek Audio Service", "Themes" };
            Console.WriteLine("Restarting AnyConnect...");
            foreach (string serviceName in serviceList)
            {
                ServiceController service = new ServiceController(serviceName, ".");
                Console.WriteLine("Stopping " + serviceName);
                try
                {
                    service.Stop();
                    Console.WriteLine(serviceName + " Stopped");
                } 
                catch
                {
                }
                Console.WriteLine("Sleeping for 5 seconds");
                System.Threading.Thread.Sleep(5000);
                Console.WriteLine("Starting " + serviceName);
                try
                {
                    service.Start();
                    Console.WriteLine(serviceName + " Started");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to start service");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Rerun script - if same error occurs, please reboot system");
                    Console.WriteLine("Press any key to close");
                    Console.ReadKey();
                    Environment.Exit(0);
                }
                Console.WriteLine("================");
            }
            Console.WriteLine("Starting AnyConnect Software");
            try
            {
                Process.Start("C:\\Program Files (x86)\\Cisco\\Cisco AnyConnect Secure Mobility Client\vpnui.exe");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to start Any Connect");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Rerun script - if same error occurs, please reboot system");
                Console.WriteLine("Press any key to close");
                Console.ReadKey();
                Environment.Exit(0);
            }
            Console.WriteLine("AnyConnect has been sucessfuly restarted");
            Console.WriteLine("Press any key to close");
            Console.ReadKey();

        }
    }
}
R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
dwb
  • 475
  • 6
  • 31
  • 1
    It sounds like you're making a .NET Core app instead of an original Windows-only .NET Framework app. .NET Core's deployment model is different to support multiple platforms. – Joe Sewell Jul 25 '19 at 19:45
  • @JoeSewell you are 100% correct, I overlooked it... wow... thanks man! (Post as an answer so I can give you credit please) – dwb Jul 25 '19 at 19:59

2 Answers2

1

You're making a .NET Core app instead of an original Windows-only .NET Framework app. While .NET Framework apps can assume all the necessary Framework DLLs and runtime components are provided by the OS (because you only run on Windows, and .NET Framework is a Windows feature), .NET Core has multiple deployment strategies to support cross-platform and side-by-side installations.

So either switch to .NET Framework (for Windows-only) or publish your .NET Core app as a framework-dependent deployment.

Joe Sewell
  • 6,067
  • 1
  • 21
  • 34
0

Here is probably something you are looking for. There is a way to compile it as executable.

Artyom Ignatovich
  • 591
  • 1
  • 3
  • 13