Creating setup file for VB.Net project in Visual Studio 2022 Community Edition
Last updated on 14 Nov. 2023
Note: This was an in-progress post around 19 Sep. 2023 but I moved on to other stuff and now in mid. Nov. 2023, I think I should mention that I do not have any plans to update or follow up on the main contents of this post. I ran into some issues with the setup file and as I now freeze the related VB.NET project software (for which I was trying to create a setup file) capturing what works in it, I felt it is best to drop the setup file from the project. I am leaving the info./knowledge shared below in this post as is without reviewing it now in mid Nov. 2023.
Some useful links
1) Setup Projects section of article: Setup and Deployment Projects, https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/wx3b589t(v=vs.100) , dated 2012, is still a useful overview though the article is over 10 years old and so some parts of the section may be inaccurate now.
2) The section, "To install the Installer Projects extension" of the following article is relevant to VB.Net. Walkthrough: Deploy a Visual C++ application by using a setup project, https://learn.microsoft.com/en-us/cpp/windows/walkthrough-deploying-a-visual-cpp-application-by-using-a-setup-project?view=msvc-170
In the above article we can ignore the Visual C++ specific content as our need is for VB.Net. This extension has to be installed first before we can create a setup project in Visual Studio 2022 Community Edition (I will refer to it later on in this article as VS 2022 CE).
Some of the other parts of the article are also relevant for VB.Net. One big difference (on which I tripped up) is that for VB.Net projects using .Net 6.0 (which is the default for my installation of VS 2022 CE) we have to use Publish Items instead of Primary Output (covered in a later point).
3) Visual Studio Installer Projects Extension and .NET 6.0, https://learn.microsoft.com/en-us/visualstudio/deployment/installer-projects-net-core?view=vs-2019
4) [One difference in following article for our needs is that we have to use Publish Items instead of Primary Output] Setup Project using Microsoft Visual Studio Installer Projects Extension, https://hexaviewtech.com/blog/setup-project-using-microsoft-visual-studio-installer-projects-extension/ .
Notes:
a) When I used Primary Output instead of Publish Items, the installer (setup.exe and setup-project-name.msi files) did not have the .exe file of my console application, and had some dll(s). Publish Items resulted in more files going into the installer including the .exe file resulting in a successful install and later run of the installed program. The output window of VS 2022 CE, while doing the build of the setup project, lists the files included in the installer.
b) Application configuration (app.config xml file) is a neat way to store data like default input file paths and/or file names. New application configuration is added to Project by Add->New Item and then choosing "Application Configuration File" (search for it if needed).
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
.....
</system.diagnostics>
<appSettings>
<add key="occupation" value="dentist"/>
<add key="TestXMLInputFilePath" value="C:\Users\Ravi-user\Desktop\OnlyRegReqRIData\BlogBookGen\VBA\Blogger\VS-ExportFileFilterByIndexList\20230801-ravisiyermisc-blog-Test.xml"/>
<add key="ProductXMLInputFilePath" value="C:\Users\Ravi-user\Desktop\OnlyRegReqRIData\BlogBookGen\VBA\Blogger\VS-ExportFileFilterByIndexList\Product.xml"/>
<add key="BlogBookFooterFilePath" value="BlogBook-Footer-Text.html"/>
<add key="BlogBook-Footer-Text" value="<p>This HTML blogbook (excluding contents links (TOC)) was created by (free and open source software)
Function BlogExportFileSearchToBook in Project ExportFileFilterAndGenBook using Microsoft Visual Basic(.Net) (VB.Net) development platform
(of Microsoft Visual Studio 2022 Community Edition). For more details about it, please visit (update later to new post on VB.Net solution):<br/>
ExportFileFilterAndGenBook: Filter Blogger XML Backup file based on date range, produce HTML Blogbook filtered by search string,
Split it and Generate Contents Links (VBA project), <a href="
https://ravisiyermisc.blogspot.com/2023/08/exportfilefilterandgenbook-vba-code-to.html">
https://ravisiyermisc.blogspot.com/2023/08/exportfilefilterandgenbook-vba-code-to.html</a>.</p>
</body></html>"/>
</appSettings>
</configuration>
--- end example app.config file ---
To read the settings in code:
Dim occupation As String
occupation = ConfigurationManager.AppSettings("occupation")
Console.WriteLine(occupation)
----
The above code did not work at first. If I recall correctly, I then added at top of file:
Imports System.Configuration
That too did not solve the problem. An error was being shown for ConfigurationManager. I used the suggested fixes option that involved installing System.Configuration.ConfigurationManager or something like that. The installation was done and then the above code was OK (no errors) and working.
c) Specific data file(s) (like BlogBook-Footer-Text.html) can be made part of installer and can be installed in same directory as executable. To access this data file we can simply use the filename without any directory specification - that picks up the file from directory of executing program. But I don't know whether that is good practice. Further during program development, the file will have to be in the debug executable directory and release executable directory as running the program from VS 2022 CE will result in code looking for the data file(s) in the debug executable directory for debug version of program and in the release executable directory for release version of the program.
d) At runtime we can figure out the directory of the running program (executable) file but I don't think that is required now:
Directory of running program for console app.: System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) . Tried it. It works.
Directory of running program for Windows Forms app.: Application.StartupPath , see https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.startuppath?view=windowsdesktop-7.0 . Yet to try it.
Comments
Post a Comment