none
Exe missing net core RRS feed

  • Question

  • Hi Experts, 

    Am new to C# and building a project in .net core. Previously I had the same project in C# .net framework based on topshelf service. The package is available for .net core but when I do a release/debug it doesn't create an exe of my solution which I used to refer to install it as a service.

    Could you please guide me how to do it in .net core to generate an exe for installing it as windows service with topshelf.

    Thanks

    Priya

    Friday, March 6, 2020 2:58 AM

Answers

  • In .NET Core we need to specify when publishing the code that it will be running on which platform e.g. Windows, Linux as It is cross platform code that is being built. There are commands for that and possible via Visual Studio as well by right clicking the Project and clicking the Publish button. For Reference the following post will help:

    https://stackoverflow.com/a/44074296/1875256

    In your case it's Windows service so the following command would work:

    dotnet publish -c Release -r win10-x64

    and from visual studio it can be set in the publish profile of project like:

    then:

    and from there we can select particular profile in your case it would be winx 86 or 64:


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites





    • Edited by Ehsan Sajjad Friday, March 6, 2020 4:50 AM
    • Marked as answer by Priya Bange Friday, March 6, 2020 6:29 AM
    Friday, March 6, 2020 4:43 AM
  • Hi Priya,

    Thank you for posting here.

    I'm not sure where your problem lies, so I will tell my steps to you for reference.

    1. Add NuGet package: TopShelf.

    2. Write a simple test code.

     class Program
        {
            static void Main(string[] args)
            {
                HostFactory.Run(x => x.Service<LoggingService>());
            }
        }
        public class LoggingService : ServiceControl
        {
            private const string _logFileLocation = @"C:\temp\servicelog.txt";
    
            private void Log(string logMessage)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(_logFileLocation));
                File.AppendAllText(_logFileLocation, DateTime.UtcNow.ToString() + " : " + logMessage + Environment.NewLine);
            }
    
            public bool Start(HostControl hostControl)
            {
                Log("Starting");
                return true;
            }
    
            public bool Stop(HostControl hostControl)
            {
                Log("Stopping");
                return true;
            }
        }

    3. From a command prompt, in the project directory, run the following :

    dotnet publish -r win-x64 -c Release

    At this time, the corresponding file will be generated in bin-> Release.

    4. Install and launch it normally.

    ConsoleApp4.exe install
    ConsoleApp4.exe start

    Everything works fine.

    Horpe this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 6, 2020 6:06 AM

All replies

  • In .NET Core we need to specify when publishing the code that it will be running on which platform e.g. Windows, Linux as It is cross platform code that is being built. There are commands for that and possible via Visual Studio as well by right clicking the Project and clicking the Publish button. For Reference the following post will help:

    https://stackoverflow.com/a/44074296/1875256

    In your case it's Windows service so the following command would work:

    dotnet publish -c Release -r win10-x64

    and from visual studio it can be set in the publish profile of project like:

    then:

    and from there we can select particular profile in your case it would be winx 86 or 64:


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites





    • Edited by Ehsan Sajjad Friday, March 6, 2020 4:50 AM
    • Marked as answer by Priya Bange Friday, March 6, 2020 6:29 AM
    Friday, March 6, 2020 4:43 AM
  • Hello, Thanks a lot for the quick guided support.Am using visual studio 2017 pro & am not getting the same options as depicted in the shared screenshots. When I try to do "Get additional publishing targets" it routes itself to some broken link. Please assist.
    Friday, March 6, 2020 5:01 AM
  • Hi Priya,

    Thank you for posting here.

    I'm not sure where your problem lies, so I will tell my steps to you for reference.

    1. Add NuGet package: TopShelf.

    2. Write a simple test code.

     class Program
        {
            static void Main(string[] args)
            {
                HostFactory.Run(x => x.Service<LoggingService>());
            }
        }
        public class LoggingService : ServiceControl
        {
            private const string _logFileLocation = @"C:\temp\servicelog.txt";
    
            private void Log(string logMessage)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(_logFileLocation));
                File.AppendAllText(_logFileLocation, DateTime.UtcNow.ToString() + " : " + logMessage + Environment.NewLine);
            }
    
            public bool Start(HostControl hostControl)
            {
                Log("Starting");
                return true;
            }
    
            public bool Stop(HostControl hostControl)
            {
                Log("Stopping");
                return true;
            }
        }

    3. From a command prompt, in the project directory, run the following :

    dotnet publish -r win-x64 -c Release

    At this time, the corresponding file will be generated in bin-> Release.

    4. Install and launch it normally.

    ConsoleApp4.exe install
    ConsoleApp4.exe start

    Everything works fine.

    Horpe this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 6, 2020 6:06 AM