isFirstRun unexpectedly false -- what am I missing?
-
Tuesday, April 19, 2011 7:50 PM
Under a certain scenario, I find, surprisingly, ApplicationDeployment.CurrentDeployment.isFirstRun's value to be false.
I know from reading here and on RobinDotNet that
1) isFirstRun will be true if the application is installed for the very first time (e.g., version 1.0.0.0)
2) isFirstRun will be true if an upgrade to the application is installed (say, from the upgrade path set in the Publish tab, e.g. version 2.0.0.0 on top of 1.0.9.3)
My scenario:
3) isFirstRun is false when the application is re-pubished with changes (e.g., change the schema of the embedded database, build, and re-publish as version 1.0.0.8 after 1.0.0.7)
I'm using Visual Studio 2010 Express, running .NET 4.0, SQL Server Compact Edition. My project is a WPF app using an embedded SQL Server CE.
I'm checking isFirstRun in the Application Startup event handler.
I need some way to keep the development database inside my VS project from stomping the production database, so I was trying to do the recommended (via Robin of RobinDotNet) transfer of contents from the .pre location database to the newly delivered database the first time a new version of the application is run.
Any ideas on why I'm getting isFirstRun as false when I do successive publish actions?
Thanks,
Cindy Rae
Answers
-
Thursday, April 28, 2011 12:53 PM
Although I still have the problem with IsFirstRun always being false, I determined a different approach that doesn't involve IsFirstRun.
If it's a ClickOnce deployment (IsNetworkDeployed) and if a predecessor database exists (in the /.pre directory), I copy it over the successor database.
Works great, but if I ever change the schema of the database, I'll have to take some steps. I'll need to add a sql script to handle the update and call the script in the logic where I copy the database.
Cindy Rae
Cindy Rae- Marked As Answer by CindyRaeWrites Friday, April 29, 2011 1:56 PM
All Replies
-
Sunday, April 24, 2011 6:25 PMModerator
Hi CindyRaeWrites,
Base on my experience and test result this property value will be reset whenever the application updated from one version to the next version.
And I also tested the three cases as you mentioned in your post, and the results were all "true".
Maybe there's something not correct in your side.
To avoid the description not clear and misunderstood, I would like you list the steps what you have did to your application, and the results.
If necessary, I also would like you can share us the screen record, to let us clear about what you did/changed to your application.
You can upload your files to the "sky driver", and then share the download link to us in your post.
If there's any concern, please feel free to let me know.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Proposed As Answer by Mike Dos ZhangMicrosoft Contingent Staff, Moderator Tuesday, April 26, 2011 10:43 AM
- Unproposed As Answer by CindyRaeWrites Tuesday, April 26, 2011 12:25 PM
-
Tuesday, April 26, 2011 1:05 PM
I’m using Visual Studio 2010 Express and SQL Server Compact Edition 3.5 to develop a WPF/XAML application with an embedded database, and I use ClickOnce to deploy the application.
I’m deploying to a location on my C: drive, and I have the option for the application to check for upgrades turned off.
The deployment variable, isFirstRun, is always false for me, when it should — apparently — be true.
My steps
1. Add the following code:
if (ApplicationDeployment.IsNetworkDeployed)
{
if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
MessageBox.Show(“IsFirstRun”);
}2. Build and publish the application via ClickOne
3. Run the application
4. See the install of the newer version of the application
5. Never see the Message Box.
Now, it’s my understanding of isFirstRun is that it should be true the first time a new version of the app is run/installed. I’m not seeing it.
For screenshots, see my blog (I see no way to attach pictures to forum postings).
Cindy Rae -
Wednesday, April 27, 2011 10:22 AMModerator
Hi CindyRaeWrites,
http://cid-bb789f72272d4858.photos.live.com/self.aspx/2011/2011Y04M/IsFristRun.zip
I made a demo to use the ClickOnce API update the application programmlly.
And insert a condition to judge if this time is the first time to run this version of the application, it also show me the expected results.
So, I would like to know your test result with this test project in your local side.
If there's any concern, please feel free to let me know.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Wednesday, April 27, 2011 2:47 PM
Mike,
Thanks for your attempt to help.
Your test application does successfully show the expected values for IsFirstRun.
However, you are deploying a Windows Form application -- not a WPF application. Also, your publish path is off the project directory (publish/) as opposed to mine, ("C:\dev\bin\SavingPlan"). You are also checking IsFirstRun after the application started up and the form was displayed.
Those are the three biggest differences -- there's others.
I did check out with my application IsFirstRun after application startup, on a button click like your test application, but IsFirstRun for me was still false.
Cindy Rae
Cindy Rae -
Thursday, April 28, 2011 11:30 AMModerator
Hi CindyRaeWrites,
I do not think so the difference places will be the probable causes.
I made a WPF application and deploy it to the "C:\dev\bin\SavingPlan" as you mentioned, and check IsFirstRun in the button click event handler.
All are the same as you request, and the results are also the expected.
So, I suggest you check your logical, you can ref my code and compare your codes with this to find the differences.
Since, I don't know how to restart the WPF application, I replace the Application.Restart method to Application.Current.ShutDown, and then start it by click the shortcut.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Thursday, April 28, 2011 12:46 PM
Mike,
I don't understand why you need to restart the application from code.
Running the application (from the shortcut or however) the first time after a publish or an upgrade, IsFirstRun should be true. Running the application (from the shortcut or however) the second time after a publish or an upgrade, IsFirstRun should be false.
And you didn't say how could I reference your code...
Thanks anyways,
Cindy Rae
Cindy Rae -
Thursday, April 28, 2011 12:53 PM
Although I still have the problem with IsFirstRun always being false, I determined a different approach that doesn't involve IsFirstRun.
If it's a ClickOnce deployment (IsNetworkDeployed) and if a predecessor database exists (in the /.pre directory), I copy it over the successor database.
Works great, but if I ever change the schema of the database, I'll have to take some steps. I'll need to add a sql script to handle the update and call the script in the logic where I copy the database.
Cindy Rae
Cindy Rae- Marked As Answer by CindyRaeWrites Friday, April 29, 2011 1:56 PM
-
Friday, April 29, 2011 11:00 AMModerator
Hi CindyRaeWrites,
I just want to to reference the upgrade logic in my demo provided in my second post.
The restart step is not necessary.
And the test result is the same as you expected in your last second post, with my demo.
Any way, it seems that you goal is not just use the IsFirstRun property, and you have solved your request, right?
If there's any concern, please feel free to let me know.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Thursday, May 05, 2011 6:06 AMModerator
Hi Cindy,
If you're using SQLCE, this might be helpful to you for installing that (or not) on the user's machine:
As for the data, I actually think it's better to move the database altogether. If you edit that sdf file at all and publish, it will carry it forward and put the old one in the .\pre folder. If you don't change it, it will put it in the data folder. I don't like the possibility of accidentally opening my database to check a table structure and wiping out the user's data. You might check out this article to help you avoid that happening to you:
As for IsFirstRun, I assume you are checking IsNetworkDeployed before accessing that, to make sure it is running as a ClickOnce application. The other thing I recommmend that you print out is the version of the ClickOnce application, so you can make sure it's actually updating it to a new version.
string ourVersion = string.Empty; //if running the deployed application, you can get the version // from the ApplicationDeployment information. If you try // to access this when you are running in Visual Studio, it will not work. if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) ourVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); else { Assembly assemblyInfo = Assembly.GetExecutingAssembly(); if (assemblyInfo != null) ourVersion = assemblyInfo.GetName().Version.ToString(); }
I've never seen a case where IsFirstRun didn't work, so you have something going on.
RobinDotNet
Click here to visit my ClickOnce blog!
Microsoft MVP, Client App Dev

