programing

Windows Forms에 ClickOnce 버전 번호를 표시하는 방법

nasanasas 2020. 11. 27. 08:10
반응형

Windows Forms에 ClickOnce 버전 번호를 표시하는 방법


두 개의 다른 위치에 배포 된 Windows Forms 응용 프로그램이 있습니다.

  • 인트라넷-ClickOnce
  • 인터넷-Windows 설치 프로그램을 통해 citrix 팜에 설치

클릭 한 번 배포 된 버전에 대한 ClickOnce 버전 번호를 표시 ApplicationDeployment.IsNetworkDeployed합니다.

if (ApplicationDeployment.IsNetworkDeployed)
        return ApplicationDeployment.CurrentDeployment.CurrentVersion;

그러나 비 클릭 응용 프로그램의 경우 어셈블리 정보에서 버전 번호를 하드 코딩하지 않는 한 clickonce 버전을 검색하는 방법을 모르겠습니다.

Clickonce가 배포되지 않은 버전의 ClickOnce 버전 번호를 자동으로 검색하는 방법이 있습니까?


아니오 나는 방법이 있다고 믿지 않습니다. ClickOnce 정보는 ClickOnce 배포에서만 사용할 수있는 매니페스트에서 온다고 생각합니다. 버전 번호를 하드 코딩하는 것이 최선의 선택이라고 생각합니다.


  1. System.Deployment프로젝트에 어셈블리 참조를 추가합니다 .

  2. 클래스 파일에서 네임 스페이스를 가져옵니다.

    VB.NET :

    Imports System.Deployment
    

    씨#:

    using System.Deployment;
    
  3. CurrentVersion속성 에서 ClickOnce 버전을 검색합니다 .

    ApplicationDeployment.CurrentDeployment.CurrentVersion속성 에서 현재 버전을 얻을 수 있습니다 . 이것은 System.Version객체를 반환 합니다.

    참고 (MSDN에서 제공) :

    CurrentVersionUpdatedVersion새 업데이트가 설치되었지만 아직을 호출하지 않은 경우 와 다릅니다 Restart. 배포 매니페스트가 자동 업데이트를 수행하도록 구성된 경우이 두 값을 비교하여 애플리케이션을 다시 시작해야하는지 결정할 수 있습니다.

    참고 : CurrentDeployment정적 속성은 응용 프로그램이 ClickOnce로 배포 된 경우에만 유효합니다. 따라서이 속성에 액세스하기 전에 먼저 속성을 확인해야합니다 ApplicationDeployment.IsNetworkDeployed. 디버그 환경에서는 항상 false를 반환합니다.

    VB.NET :

    Dim myVersion as Version
    
    If ApplicationDeployment.IsNetworkDeployed Then
       myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion
    End If
    

    씨#:

    Version myVersion;
    
    if (ApplicationDeployment.IsNetworkDeployed)
       myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
    
  4. Version개체 사용 :

    여기에서 "정보"양식에 다음과 같이 라벨의 버전 정보를 사용할 수 있습니다.

    VB.NET :

    versionLabel.Text = String.Concat("ClickOnce published Version: v", myVersion)
    

    씨#:

    versionLabel.Text = string.Concat("ClickOnce published Version: v", myVersion);
    

    ( Version객체는 네 부분으로 된 번호 (major.minor.build.revision)로 형식이 지정됩니다.)


새 버전을 내놓을 때마다 주 어셈블리의 어셈블리 버전을 CLickOnce 버전과 동일하게 만들기 만하면됩니다. 그런 다음 clickonce가 아닌 응용 프로그램으로 실행되면 Reflection을 사용하여 어셈블리 버전을 선택하십시오.


스레드 확인을 시도하십시오.

if (ApplicationDeployment.IsNetworkDeployed)
{
    if (ApplicationDeployment.CurrentDeployment.CurrentVersion != ApplicationDeployment.CurrentDeployment.UpdatedVersion)
    {
        Application.ExitThread();
        Application.Restart();
    }
}

하드 코드 또는 ... 데이터베이스에서 버전 (파일, 어셈블리, 배포)을 추적합니다. 어셈블리를 사용하여 데이터베이스를 호출하고 배포 버전을 가져옵니다.

This assumes that you are incrementing your versions in a logical way such that each version type has a relationship. It's a lot of work for such a minor problem. I'd personally go with Jared's solution; although I hate hard coding anything.


not that it matters three years later, but I ended up just parsing the manifest file with xml reader.


To expand on RobinDotNet's solution:

Protip: You can automatically run a program or script to do this for you from inside the .csproj file MSBuild configuration every time you build. I did this for one Web application that I am currently maintaining, executing a Cygwin bash shell script to do some version control h4x to calculate a version number from Git history, then pre-process the assembly information source file compiled into the build output.

A similar thing could be done to parse the ClickOnce version number out of the project file i.e., Project.PropertyGroup.ApplicationRevision and Project.PropertyGroup.ApplicationVersion (albeit I don't know what the version string means, but you can just guess until it breaks and fix it then) and insert that version information into the assembly information.

I don't know when the ClickOnce version is bumped, but probably after the build process so you may need to tinker with this solution to get the new number compiled in. I guess there's always /*h4x*/ +1.

I used Cygwin because *nix scripting is so much better than Windows and interpreted code saves you the trouble of building your pre-build program before building, but you could write the program using whatever technology you wanted (including C#/.NET). The command line for the pre-processor goes inside the PreBuildEvent:

<PropertyGroup>
  <PreBuildEvent>
    $(CYGWIN_ROOT)bin\bash.exe --login -c refresh-version
  </PreBuildEvent>
</PropertyGroup>

As you'd imagine, this happens before the build stage so you can effectively pre-process your source code just before compiling it. I didn't want to be automatically editing the Properties\AssemblyInfo.cs file so to play it safe what I did was create a Properties\VersionInfo.base.cs file that contained a text template of a class with version information and was marked as BuildAction=None in the project settings so that it wasn't compiled with the project:

using System.Reflection;
using EngiCan.Common.Properties;

[assembly: AssemblyVersion("0.$REVNUM_DIV(100)$.$REVNUM_MOD(100)$.$DIRTY$")]
[assembly: AssemblyRevisionIdentifier("$REVID$")]

(A very dirty, poor-man's placeholder syntax resembling Windows' environment variables with some additional h4x thrown in was used for simplicity's/complexity's sake)

AssemblyRevisionIdentifierAttribute was a custom attribute that I created to hold the Git SHA1 since it is much more meaningful to developers than a.b.c.d.

My refresh-version program would then copy that file to Properties\VersionInfo.cs, and then do the substitution of the version information that it already calculated/parsed (I used sed(1) for the substitution, which was another benefit to using Cygwin). Properties\VersionInfo.cs was compiled into the program. That file can start out empty and you should ignore it by your version control system because it is automatically changing and the information to generate it is already stored elsewhere.


Using a build component, you could read the click-once version from the project file and write it automatically to the assembly info so both of them are in sync.


Do a thread verification, insert harded code...

참고URL : https://stackoverflow.com/questions/1098112/how-to-display-clickonce-version-number-on-windows-forms

반응형