How to show application version in VS.NET Deployment Project? - c#

I have set up a Deployment Project for my application. The problem is that I want to show application version (eg. MyApplication 1.2.3.1) during installation so the user can see the version before installing.
The only way I can think of is to modify the WelcomeText in Welcome dialog. Is there an easier or more elegant way to achieve this?

You should be able to use the Windows Installer ProductVersion property for this. If you change the Welcome dialog's WelcomeText property to:
The installer will guide you through the steps required to install [ProductName] [ProductVersion] on your computer.
Then you can change the Deployment Project's Version property and have the value automatically displayed. Any string-based property can do this; just use the [] syntax to have the value inserted.
For other properties that are provided out of the box, see the Windows Installer Property Reference

You can get the version number that is set in the executing AssemblyInfo.cs using this code
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
Similarly if you want to get the version number for a specific assembly you can use
System.Reflection.Assembly.GetAssembly([type in my assembly]).GetName().Version.ToString()
You could then change the welcome text automatically at runtime.

Related

ClickOnce Upgrade Settings Failing [duplicate]

I've updated one of my WPF apps from .NET Framework 4.7 to .NET 5. It uses the ClickOnce Installer to install updates. Since the change to .NET 5, I'm using the AssemblyVersion for setting the version instead of rely on the ClickOnce version, but the ClickOnce ApplicationVersion is also set.
Additionally I'm using application settings (user.config file) to store some user settings. Since the update to .NET 5, the user settings are always deleted after an update. I tought it is because of the different AssemblyVersion, but as far as I understand this site, the config file sould be merged by ClickOnce automatically.
Also a Settings.Default.Upgrade() didn't change anything. The user.config is still not existing for the updated version and therefore, no settings could be loaded from previous verions.
Did I understand something wrong? Should it work or do I have to change anything?
Thank you in advance for your help :)
I have had the same issue. Signing the assembly of the WPF project did the trick for me and fixed the problem.
Project properties -> Singing -> "Sign the assembly"
Create a strong name key file
Putting this in the main form loaded event worked for me:
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
Set a Setting in settings called UpgradeRequired to true
This way every time the program gets updated, the Upgrade method gets called and settings get carried forward to the next version.

ClickOnce and .NET 5: User settings not updated

I've updated one of my WPF apps from .NET Framework 4.7 to .NET 5. It uses the ClickOnce Installer to install updates. Since the change to .NET 5, I'm using the AssemblyVersion for setting the version instead of rely on the ClickOnce version, but the ClickOnce ApplicationVersion is also set.
Additionally I'm using application settings (user.config file) to store some user settings. Since the update to .NET 5, the user settings are always deleted after an update. I tought it is because of the different AssemblyVersion, but as far as I understand this site, the config file sould be merged by ClickOnce automatically.
Also a Settings.Default.Upgrade() didn't change anything. The user.config is still not existing for the updated version and therefore, no settings could be loaded from previous verions.
Did I understand something wrong? Should it work or do I have to change anything?
Thank you in advance for your help :)
I have had the same issue. Signing the assembly of the WPF project did the trick for me and fixed the problem.
Project properties -> Singing -> "Sign the assembly"
Create a strong name key file
Putting this in the main form loaded event worked for me:
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
Set a Setting in settings called UpgradeRequired to true
This way every time the program gets updated, the Upgrade method gets called and settings get carried forward to the next version.

How to get the publish version of a WPF application

I want my WPF application publish version. I tried using the answer for this question. It works but the problem is we can manually change the values there. I want to know how many times my project was actually published (don't need version number. Just how many times did I publish my application). Can this be done?
Using Click Once, each time you publish, Visual Studio will change the number automatically. It will increment the value each time you publish. Your problem is that you have manually changed the number. The solution is to publish and just let Visual Studio update the value... you should notice that your project needs to be saved once you have published. This is because Visual Studio just incremented the value for you.
UPDATE >>>
If you want to access the published version from code (which you should have made clear in your question), then you can use this code, but you have to ensure that the application is network deployed first... that means that it has actually been published, so it won't work while you are debugging. Try this:
private string GetPublishedVersion()
{
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
return System.Deployment.Application.ApplicationDeployment.CurrentDeployment.
CurrentVersion.ToString();
}
return "Not network deployed";
}
You may be confused by 2 sets of numbers. Please note that you can set version of your WPF app in TWO different places:
Project Properties / Publish tab / Publish Version
AssemblyVersion declared in AssemblyInfo.cs file, which you can find if you expand Project Properties node in Solution Explorer.
They are similar in the sense that they both provides 4 numbers: major, minor, build and revision. The difference is that Publish Version is only available if the app was actually Published (i.e. Installed). It is not available in your debug session nor if you just copy the executable to another machine and run it there. SO, if you just need to track version of your EXE file, use AssemblyInfo.cs.
Correspondingly, to read the data use the following code:
1 To read Publish version (declared in Publish tab)
using System.Deployment.Application;
ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
Note that in this case: a) you need to add reference to System.Deployment assembly, b) if the app was not deployed, it won't work.
2 To read Assembly Version (declared in AssemblyInfo.cs)
Assembly.GetExecutingAssembly().GetName().Version;
This one always works.
Universal solution if we get application version from not startup assembly:
var version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
string appVersion = $"{version.Major}.{version.Minor}";
GetEntryAssembly give version of startup project.
var obj=Assembly.GetExecutingAssembly().GetName().Version;
string version= string.Format("Application Version {0}.{1}", obj.Build, obj.Revision);
OR
string version= string.Format("Application Version {0}.{1}", obj.Major, obj.Minor);
whichever properties suits you.

C# Install - Change a custom folder location using install dialog

I am trying to install a windows service using a visual studio setup project. All is going well except I want the user to be able to use the install dialog to specify the location of a custom folder to be created during installation.
I've added a Textboxes dialog that stores a folder location in an Install Property (PATHPROPERTY in this example) but I can't figure out how to use that to change the path of a folder I'm creating during the installation. I set the 'Default Location' Property of the custom folder in the 'File System' menu to:
"[PATHPROPERTY]\folder"
But when I change the path in the install dialog, the folder is created at the default location of PATHPROPERTY, not what I change it to during install. So it seems like the folder is created before I reach the point in my dialog where I ask for the path.
I noticed that there is a Property Property for the folder that I can set and supposedly use to modify the location of the folder during installation, and I've seen some articles suggesting that this can be used to set the location using a command line flag. But I would like to be able to use the install dialog, then possibly set this property in my installer class, but I haven't found any documentation on how to do that yet..
I also found something about Session.Property to set the property but the documentation wasn't clear on how to use this.
Any help would be much appreciated.
Oh. Also. I'm targeting .NET 3.5.
So PATHPROPERTY returns the custom folder location user has selected, If thats the case you have to set that property to "Property" attribute.
Also make sure in the User Interface Editor you are getting the user input before installation starts. (You can move up and down the UI to required position)

Windows Service not appearing in services list after install

I've created a windows service in C#, using Visual Studio 2008
I pretty much followed this:
http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
I created a setup project, as instructed to in the article, and ran it...
it installs my service to C:\Program Files\Product etc.... however, it does not then appear in the services list..
What am I missing?
The most important part of the article you linked, is here
To add a custom action to the setup project
1.In Solution Explorer, right-click the setup project, point to View, then
choose Custom Actions. The Custom
Actions editor appears.
2.In the Custom Actions editor, right-click the Custom Actions node
and choose Add Custom Action. The
Select Item in Project dialog box
appears.
3.Double-click the application folder in the list box to open it, select
primary output from MyNewService
(Active), and click OK. The primary
output is added to all four nodes of
the custom actions � Install, Commit,
Rollback, and Uninstall.
4.Build the setup project.
If you skip these steps, your setup project will build and copy your files to the correct directory; however, they will not register your binary as a service without these steps.
I should also note that this works for older versions of Visual Studio that had/have the built-in Setup/Deployment project template. The newer versions of Visual Studio have different setup/deployment projects (some requiring third party software.)
I'd recommend looking into WiX Toolset and check here for WiX Installation of Windows Services.
I got owned in the face by this one, so I'm putting it here just in case anyone else runs into it.
If you followed the instructions in the guides but are still having issues installing, ensure your Installer class is public. Internal won't work.
I had this same issue and then I realized that I never set the parent for the ServiceInstaller.
Double-click on your project installer. The designer should show a Service Installer and Process Installer. When you click on either and view the properties you should note the Parent attribute which must both be set to the class name of the Project Installer.
Or, if you do it in code, make sure you set:
serviceInstaller.Parent = this;
and
serviceProcessInstaller.Parent = this;
When installing services, I would highly recommend using NSSM, which worked well for me for all my WinService needs. It can install any executable (even if .bat, .cmd) as a service, and guarantees your service is always up and running.
To use this tool:
Download from here
And follow the instructions here
Then check the services list, it should be there, up, and running.
Follow these instructions, they worked for me. For the setup specifically, that part is near the bottom of the article.
MSDN: Walkthrough: Creating a Windows Service
In Visual Studio 2013 I ran into the same problem using InstallShield template for service application. But it works like charm when using Setup Project template https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d
so download Setup Project template close your Studio, run this installation and start your Studio, this will work.
Dunn.
Here is a good tutorial from tgeek001 from CodeProject.com that helped me. It includes several things I didn't see in the posts above:
1. Event handler code to stop the service before uninstalling it
2. Specific conditions and properties in the Custom Actions code to set in order to prevent failures (these fixed the Error 1001 that I experienced while following the instructions in the accepted answer above)
3. Win Service property "Remove Previous Version" dropdown set to true
http://www.codeproject.com/Tips/575177/Window-Service-Deployment-using-VS
The following is from the tutorial for Custom Actions Settings (case matters):
Install, set the Condition property to the following: "NOT (Installed or PREVIOUSVERSIONSINSTALLED)"
Uninstall, set the Condition property to: "NOT UPGRADINGPRODUCTCODE"
Commit: set "Custom Action Data" field to: /OldProductCode="[PREVIOUSVERSIONSINSTALLED]"
Lastly, in the WinService project, make sure to set the dropdown "Remove Previous Versions" to true.
cheers
I discovered that your installer class much be in the same project as the Service. The installer cannot exist in a library project referenced by the Service.
remember to check the name you've given your service before you search. (right click-> properties->check the service name

Categories