버전 번호 자동 업데이트
내 응용 프로그램의 버전 속성을 각 빌드마다 증가시키고 싶지만 Visual Studio (2005/2008)에서이 기능을 활성화하는 방법을 잘 모르겠습니다. AssemblyVersion을 1.0. *로 지정하려고했지만 원하는 것을 정확히 얻지 못했습니다.
또한 설정 파일을 사용하고 있으며 이전 시도에서 어셈블리 버전이 변경되었을 때 응용 프로그램이 다른 디렉터리에서 설정 파일을 찾았 기 때문에 설정이 기본값으로 재설정되었습니다.
버전 번호를 1.1.38 형식으로 표시하여 사용자가 문제를 발견하면 사용중인 버전을 기록하고 이전 릴리스가있는 경우 업그레이드하도록 지시 할 수 있기를 바랍니다.
버전 관리가 어떻게 작동하는지에 대한 간단한 설명도 감사하겠습니다. 빌드 및 개정 번호는 언제 증가합니까?
"내장"항목으로는 불가능합니다. 1.0. * 또는 1.0.0. *을 사용하면 개정 및 빌드 번호가 코드화 된 날짜 / 타임 스탬프로 대체되므로 일반적으로 좋은 방법입니다.
자세한 내용 은 / v 태그 의 어셈블리 링커 설명서를 참조하십시오 .
자동으로 숫자를 늘리려면 AssemblyInfo 태스크를 사용하십시오.
빌드 번호를 자동으로 늘리도록 구성 할 수 있습니다.
2 가지 고차가 있습니다.
- 버전 문자열의 4 개 숫자는 각각 65535로 제한됩니다. 이는 Windows 제한 사항이며 수정 될 가능성이 낮습니다.
- Subversion과 함께 사용하려면 약간의 변경이 필요합니다.
버전 번호를 검색하는 것은 매우 쉽습니다.
Version v = Assembly.GetExecutingAssembly().GetName().Version;
string About = string.Format(CultureInfo.InvariantCulture, @"YourApp Version {0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision);
그리고 명확히하기 위해 : .net 또는 적어도 C #에서 빌드는 실제로 세 번째 번호이며 일부 사람들 (예 : Major.Minor.Release.Build에 익숙한 Delphi 개발자)이 예상 할 수있는 네 번째 번호가 아닙니다.
.net에서는 Major.Minor.Build.Revision입니다.
VS.NET은 어셈블리 버전을 1.0. *로 기본 설정하고 자동 증분시 다음 논리를 사용합니다. 빌드 부분을 2000 년 1 월 1 일 이후 일 수로 설정하고 수정 부분을 자정 이후의 초 수로 설정합니다. 현지 시간을 2로 나눈 값입니다. 이 MSDN 문서를 참조하십시오 .
어셈블리 버전은 assemblyinfo.vb 또는 assemblyinfo.cs 파일에 있습니다. 파일에서 :
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>
제품 버전이 필요할 때마다 다음을 사용하여 마지막 빌드 날짜를 표시하는 것이 잘 작동 함을 발견했습니다.
System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString("yyyy.MM.dd.HH.mm.ss")
다음과 같은 것에서 버전을 가져 오려고 시도하는 대신 :
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false);
object attribute = null;
if (attributes.Length > 0)
{
attribute = attributes[0] as System.Reflection.AssemblyFileVersionAttribute;
}
어떤 소스 제어 시스템을 사용하고 있습니까?
거의 모든 파일에는 파일이 체크인 될 때 확장되는 $ Id $ 태그 형식이 있습니다.
나는 보통 이것을 버전 번호로 표시하기 위해 어떤 형태의 해커 리를 사용합니다.
다른 대안은 날짜를 빌드 번호로 사용하는 것입니다 : 080803-1448
[Visual Studio 2017, .csproj 속성]
PackageVersion / Version / AssemblyVersion 속성 (또는 기타 속성)을 자동으로 업데이트하려면 먼저 Microsoft.Build.Utilities.Task
현재 빌드 번호를 가져올 새 클래스를 만들고 업데이트 된 번호를 다시 보냅니다 (해당 클래스에 대해서만 별도의 프로젝트를 만드는 것이 좋습니다).
I manually update the major.minor numbers, but let MSBuild to automatically update the build number (1.1.1, 1.1.2, 1.1.3, etc. :)
using Microsoft.Build.Framework;
using System;
using System.Collections.Generic;
using System.Text;
public class RefreshVersion : Microsoft.Build.Utilities.Task
{
[Output]
public string NewVersionString { get; set; }
public string CurrentVersionString { get; set; }
public override bool Execute()
{
Version currentVersion = new Version(CurrentVersionString ?? "1.0.0");
DateTime d = DateTime.Now;
NewVersionString = new Version(currentVersion.Major,
currentVersion.Minor, currentVersion.Build+1).ToString();
return true;
}
}
Then call your recently created Task on MSBuild process adding the next code on your .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
...
<UsingTask TaskName="RefreshVersion" AssemblyFile="$(MSBuildThisFileFullPath)\..\..\<dll path>\BuildTasks.dll" />
<Target Name="RefreshVersionBuildTask" BeforeTargets="Pack" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<RefreshVersion CurrentVersionString="$(PackageVersion)">
<Output TaskParameter="NewVersionString" PropertyName="NewVersionString" />
</RefreshVersion>
<Message Text="Updating package version number to $(NewVersionString)..." Importance="high" />
<XmlPoke XmlInputPath="$(MSBuildProjectDirectory)\mustache.website.sdk.dotNET.csproj" Query="/Project/PropertyGroup/PackageVersion" Value="$(NewVersionString)" />
</Target>
...
<PropertyGroup>
..
<PackageVersion>1.1.4</PackageVersion>
..
When picking Visual Studio Pack project option (just change to BeforeTargets="Build"
for executing the task before Build) the RefreshVersion code will be triggered to calculate the new version number, and XmlPoke
task will update your .csproj property accordingly (yes, it will modify the file).
When working with NuGet libraries, I also send the package to NuGet repository by just adding the next build task to the previous example.
<Message Text="Uploading package to NuGet..." Importance="high" />
<Exec WorkingDirectory="$(MSBuildProjectDirectory)\bin\release" Command="c:\nuget\nuget push *.nupkg -Source https://www.nuget.org/api/v2/package" IgnoreExitCode="true" />
c:\nuget\nuget
is where I have the NuGet client (remember to save your NuGet API key by calling nuget SetApiKey <my-api-key>
or to include the key on the NuGet push call).
Just in case it helps someone ^_^.
Some time ago I wrote a quick and dirty exe that would update the version #'s in an assemblyinfo.{cs/vb} - I also have used rxfind.exe (a simple and powerful regex-based search replace tool) to do the update from a command line as part of the build process. A couple of other helpfule hints:
- separate the assemblyinfo into product parts (company name, version, etc.) and assembly specific parts (assembly name etc.). See here
- Also - i use subversion, so I found it helpful to set the build number to subversion revision number thereby making it really easy to always get back to the codebase that generated the assembly (e.g. 1.4.100.1502 was built from revision 1502).
If you want an auto incrementing number that updates each time a compilation is done, you can use VersionUpdater from a pre-build event. Your pre-build event can check the build configuration if you prefer so that the version number will only increment for a Release build (for example).
참고URL : https://stackoverflow.com/questions/650/automatically-update-version-number
'IT story' 카테고리의 다른 글
웹 글꼴을 합법적으로 사용하는 방법은 무엇입니까? (0) | 2020.08.12 |
---|---|
여러 도메인에 대한 단일 사인온 [닫힘] (0) | 2020.08.12 |
UIView의 setNeedsLayout, layoutIfNeeded 및 layoutSubviews 간의 관계는 무엇입니까? (0) | 2020.08.12 |
하드웨어없이 CUDA 프로그래밍을위한 GPU 에뮬레이터 (0) | 2020.08.12 |
십자 축을 채우기 위해 아이들을 늘리는 방법? (0) | 2020.08.12 |