Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When support the deployment version of Clickonce? #1153

Closed
maikebing opened this issue Feb 11, 2017 · 9 comments
Closed

When support the deployment version of Clickonce? #1153

maikebing opened this issue Feb 11, 2017 · 9 comments

Comments

@maikebing
Copy link

Is already supported but i will not use it? Still do not support?

@gep13
Copy link
Member

gep13 commented Feb 11, 2017

@maikebing what sort of support are you looking for?

@maikebing
Copy link
Author

The release of the ClickOnce version number

@fwinkelbauer
Copy link

fwinkelbauer commented Feb 22, 2017

@gep13 ClickOnce doesn't care about the information provided in AssemblyInfo.cs. All configuration for ClickOnce is provided in the .csproj file. An example would be:

    <ApplicationRevision>116</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>

or

    <ApplicationVersion>1.0.0.116</ApplicationVersion>

%2a is a replacement character (*) and inserts the <ApplicationRevision> data. In other words: both snippets result in the same version 1.0.0.116. ClickOnce uses a bunch of other XML configuration tags, but these two define the current version. (Examples of other tags include: upload location, auto update enabled/disabled, enforcing a minimum version and many more)

So if I would like to use GitVersion with ClickOnce I'd have to write a script which either throws the output of GitVersion into a .csproj file, or I'd write a script which reads the AssemblyInfo.cs after running GitVersion to inject the version data into .csproj.

I might look into this on the weekend to give a better picture

Edit: I am not sure if ClickOnce would allow non-numerical data or if a three number format (A.B.C) can be used instead of the A.B.C.D format from above

@fwinkelbauer
Copy link

fwinkelbauer commented Feb 22, 2017

@gep13 I've looked more into this. As far as I can tell my assumption was right: ClickOnce only supports numerical version strings in the form A.B.C.D. This means that the properties AssemblySemVer and MajorMinorPatch (as found in the JSON output of GitVersion) would be a perfect fit.

Solution Draft 1

Here is a small snippet which injects the version information into a .csproj file:

public static void WriteClickOnceVersionABCD(string csproj, string version)
{
    var doc = new XmlDocument();
    doc.Load(csproj);

    var versionNodes = doc.GetElementsByTagName("ApplicationVersion");

    foreach (XmlNode node in versionNodes)
    {
        node.InnerText = version;
    }

    var revisionNodes = doc.GetElementsByTagName("ApplicationRevision");

    for (int i = revisionNodes.Count - 1; i >= 0; i--)
    {
        revisionNodes[i].ParentNode.RemoveChild(revisionNodes[i]);
    }

    doc.Save(csproj);
}

This code will:

  • Search for all tags named ApplicationVersion and inject a A.B.C.D style version
  • Search and remove all tags named ApplicationRevision as they would not be used (no 2%a in ApplicationVersion)

Solution Draft 2

Another approach could look like this:

public static void WriteClickOnceVersionABC(string csproj, string version)
{
    var doc = new XmlDocument();
    doc.Load(csproj);

    var revisionNodes = doc.GetElementsByTagName("ApplicationRevision");

    for (int i = revisionNodes.Count - 1; i >= 0; i--)
    {
        revisionNodes[i].ParentNode.RemoveChild(revisionNodes[i]);
    }

    var versionNodes = doc.GetElementsByTagName("ApplicationVersion");

    foreach (XmlNode node in versionNodes)
    {
        node.InnerText = $"{version}.%2a";
        var revisionNode = doc.CreateElement("ApplicationRevision", node.NamespaceURI);
        revisionNode.InnerText = "0";
        node.ParentNode.InsertAfter(revisionNode, node);
    }

    doc.Save(csproj);
}
  • Remove all current ApplicationRevision tags
  • Search for all tags named ApplicationVersion and inject a A.B.C.%2a style version
  • Add ApplicationRevision tags with value 0

The benefit of this approach is that it is a little bit more flexible. The A.B.C.%2a style version can be used to inject a rolling build number into a ClickOnce application.

Is this something you would like to include in GitVersion, or is this requirement in general "too specific"?

Edit: Added both code snippets

@thoemmi
Copy link
Contributor

thoemmi commented Feb 22, 2017

@fwinkelbauer @maikebing
I'm using GitVersion in an internal ClickOnce application. It's quite easy to setup. I've added following target in my .csproj file:

<Target Name="MyApp_SetClickOnceVersion" AfterTargets="UpdateAssemblyInfo" DependsOnTargets="GetVersion" BeforeTargets="_DeploymentComputeClickOnceManifestInfo">
  <CreateProperty Value="$(GitVersion_AssemblySemVer)">
    <Output TaskParameter="Value" PropertyName="ApplicationVersion" />
  </CreateProperty>
  <!-- for VSTO -->
  <CreateProperty Value="$(ApplicationVersion)">
    <Output TaskParameter="Value" PropertyName="PublishVersion" />
  </CreateProperty>
  <Message Text="ApplicationVersion: $(ApplicationVersion)" Importance="High" />
</Target>

This will set the properties ApplicationVersion and PublishVersion dynamically to the correct value.

@fwinkelbauer
Copy link

@thoemmi yeah I agree, this is another simple solution that works. I was providing all this input so that we could consider if it is a good idea to integrate ClickOnce support into GitVersion. This way we wouldn't need to touch the .csproj file at all.

By the way what does the PublishVersion tag do? I know that this is the name provided in the Visual Studio settings panel, but from what I know ApplicationVersion and ApplicationRevision are the only tags that influence the ClickOnce version. Am I missing something?

@thoemmi
Copy link
Contributor

thoemmi commented Feb 22, 2017

I've implemented it already a couple of month ago. If I remember correcty, PublishVersion was necessary to get the deployment working, i.e. calling msbuild.exe with publish target.

@JakeGinnivan
Copy link
Contributor

Agree with the general consensus that it's easy to workaround not putting support in. If we did the solution wouldn't work for those using mage anyways, so it wouldn't even be a complete solution.

I have written up a more complete response at #1152, but the tl;dr is that I do not want us to put built in updating anything into GitVersion. Instead we should spin up a collection of smaller utilities which take the output of GitVersion and do the updates. This reduces the complexity and scope of GitVersion which is a good thing.

@JakeGinnivan
Copy link
Contributor

If anyone would like to take these workarounds and add them into the docs, that would be great though :) pull requests welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants