ClickOnce - automatically making all builds required?
Is there a script for always making all my published builds required, update-wise? I want to force an update开发者_StackOverflow社区 to all my customers no matter what, however, they are asked whether or not they want to update, even after using the ClickOnce deployment API.
Simply you can achieve by adding below <target>
tag in your project's .csproj
file.
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
// Other Tags ...
<Target Name="AutoSetMinimumRequiredVersion" BeforeTargets="GenerateDeploymentManifest">
<FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
<Output PropertyName="MinimumRequiredVersion" TaskParameter="OutputVersion" />
</FormatVersion>
<FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
<Output PropertyName="_DeploymentBuiltMinimumRequiredVersion" TaskParameter="OutputVersion" />
</FormatVersion>
</Target>
// Other Tags ...
</Project>
It will automatically make your each publish/update mandatory without doing any extra stuff.
Yes, you can force an upgrade for all customers by requiring a minimal version. This is so that you can make incompatible server changes.
From MSDN:
To mark an update as required, click Specify a minimum required version for this application in the Application Updates dialog box, then specify the publish version (Major, Minor, Build, Revision), which specifies the lowest version number of the application that can be installed.
I ended up using the ClickOnce deployment API, where I have much more control over the process. The trick is to set the application as a CD-ROM application that runs 100% offline. Then, using simple ClickOnce code, a silent update can be performed.
private void Update()
{
try
{
ApplicationDeployment.CurrentDeployment.CheckForUpdateCompleted += new CheckForUpdateCompletedEventHandler(CurrentDeployment_CheckForUpdateCompleted);
ApplicationDeployment.CurrentDeployment.UpdateCompleted += new System.ComponentModel.AsyncCompletedEventHandler(CurrentDeployment_UpdateCompleted);
ApplicationDeployment.CurrentDeployment.CheckForUpdateAsync();
}
catch (Exception)
{
}
}
void CurrentDeployment_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
{
try
{
if (e.UpdateAvailable)
{
ApplicationDeployment.CurrentDeployment.UpdateAsync();
}
}
catch (InvalidOperationException)
{
}
}
void CurrentDeployment_UpdateCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//TODO: update completion code here
}
精彩评论