2017-11-02 7 views
1

스플래시 화면에 동적 컨텐츠를 추가하는 방법에 대해서는 Kent Boogaart의 excellent article을 따랐습니다. 이제는 스플래시 화면에서 버전 번호를 볼 수 있다는 점에서 모든 것이 작동합니다. 그러나 문제는 기사에서 $(Version) 속성을 사용하고 있는데, 내 경우에는 1.0.0.0입니다.스플래시 화면에 어셈블리 버전 작성하기

나는 shared AssemblyInfo.vb을 사용 중이며이 파일에서 다음 메이저/마이너/빌드/개정 번호를 가져 와서 시작 화면에 그려야합니다. 공유 AssemblyInfo 파일에는 2.5.*과 같은 버전 번호가 들어 있습니다. MSBuild (2.5.abc.xyz)가 생성 할 실제 번호가 필요합니다.

나는 어셈블리에서 버전 번호를 얻기 위해 UsingTask 내부 반사를 사용하는 방법에 대한 생각했지만,이 작업 전에 빌드 프로세스를 를 실행하기 때문에, 조립은 아직 다음에 생성 될 버전 번호가없는 짓다. 또한 어셈블리가 존재하지 않을 수도 있습니다 (예 : 빌드하기 전에 Clean 명령).

MSBuild 커뮤니티 작업을 설치했지만 SvnVersion 작업을 제외한 모든 항목을 볼 수 없습니다.

생성 된 버전 번호를 UsingTask으로 보내 주실 수 있습니까?

+0

VB 프로젝트의 기본 'SplashScreen'을 추가하십시오. 응용 프로그램의 개정 번호가 들어 있습니다. – kiLLua

+0

@kiLLua : 이것은 WinForms 프로젝트가 아닙니다. WPF SplashScreen 템플릿은 단순히 텍스트가없는 PNG 파일입니다. – dotNET

+0

실행 어셈블리가 * next * 빌드 어셈블리의 버전을 어떻게 알 수 있습니까? 현재 실행중인 응용 프로그램의 버전을 표시하지 않는 이유는 무엇입니까? – mm8

답변

1

마침내! 동일한 작업을 수행하려는 다른 사용자의 경우 다음 단계를 수행합니다. 솔루션 디렉토리에있는 공유 AssemblyInfo를 사용하고 있다고 가정합니다 (기본 AssemblyInfo에서도 작동 할 수 있지만 그에 따라 경로와 파일 이름을 조정해야합니다) :

  1. 컴퓨터에 MSBuild Community Tasks을 다운로드하여 설치하십시오.
  2. 대상 파일 (확장자가 .targets 인 간단한 XML 파일)을 프로젝트에 추가하십시오.
  3. UsingTask을 Kent Boogaart의 기사에 실 었는데이 파일에 질문에 링크되어 있습니다. 그러면 스플래시 이미지에 실제 버전 쓰기가 수행됩니다.
  4. 사용 <Version>, <FileUpdate><AddTextToImage> 작업 공유 어셈블리 정보 파일 및 스플래시 이미지에 새 버전 번호를 작성 (MSBuild를 사용할 수는 처음 두가, 세 번째는 우리가 3 단계에서 추가 UsingTask에서이다).

마지막 .targets 파일은 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <UsingTask TaskName="AddTextToImage" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> 
    <ParameterGroup> 
     <InputPath ParameterType="System.String" Required="true" /> 
     <OutputPath ParameterType="System.String" Required="true" /> 
     <TopMiddlePoint ParameterType="System.String" Required="true" /> 
     <Text1 ParameterType="System.String" Required="true" /> 
     <Text2 ParameterType="System.String" Required="false" /> 
     <Text3 ParameterType="System.String" Required="false" /> 
    </ParameterGroup> 
    <Task> 
     <Reference Include="WindowsBase" /> 
     <Reference Include="PresentationCore" /> 
     <Reference Include="PresentationFramework" /> 
     <Reference Include="System.Xaml" /> 
     <Using Namespace="System" /> 
     <Using Namespace="System.Globalization" /> 
     <Using Namespace="System.IO" /> 
     <Using Namespace="System.Windows" /> 
     <Using Namespace="System.Windows.Media" /> 
     <Using Namespace="System.Windows.Media.Imaging" /> 
     <Code Type="Fragment" Language="cs"> 
     <![CDATA[   
       var originalImageSource = BitmapFrame.Create(new Uri(InputPath)); 

       var visual = new DrawingVisual(); 

       using (var drawingContext = visual.RenderOpen()) 
       { 
       drawingContext.DrawImage(originalImageSource, new Rect(0, 0, originalImageSource.PixelWidth, originalImageSource.PixelHeight)); 

       var typeFace = new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal); 
       var formattedText = new FormattedText(Text1, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeFace, 18, Brushes.Red); 
       var topMiddlePoint = Point.Parse(TopMiddlePoint); 
       var point = new Point(topMiddlePoint.X - (formattedText.Width/2), topMiddlePoint.Y); 
       drawingContext.DrawText(formattedText, point); 

       if(!string.IsNullOrEmpty(Text2)) 
       { 
        formattedText = new FormattedText(Text2, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeFace, 18, Brushes.Red); 
        topMiddlePoint.Y += formattedText.Height + 5; 
        point = new Point(topMiddlePoint.X - (formattedText.Width/2), topMiddlePoint.Y); 
        drawingContext.DrawText(formattedText, point); 
       } 

       if(!string.IsNullOrEmpty(Text3)) 
       { 
        formattedText = new FormattedText(Text3, System.Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeFace, 18, Brushes.Red); 
        topMiddlePoint.Y += formattedText.Height + 5; 
        point = new Point(topMiddlePoint.X - (formattedText.Width/2), topMiddlePoint.Y); 
        drawingContext.DrawText(formattedText, point); 
       } 

       drawingContext.Close(); 
       } 

       var renderTargetBitmap = new RenderTargetBitmap(originalImageSource.PixelWidth, originalImageSource.PixelHeight, originalImageSource.DpiX, originalImageSource.DpiY, PixelFormats.Pbgra32); 

       renderTargetBitmap.Render(visual); 

       var bitmapFrame = BitmapFrame.Create(renderTargetBitmap); 

       BitmapEncoder encoder = new PngBitmapEncoder(); 

       encoder.Frames.Add(bitmapFrame); 

       using (var stream = File.OpenWrite(OutputPath)) 
       { 
       encoder.Save(stream); 
       stream.Close(); 
       } 
      ]]> 
     </Code> 
    </Task> 
    </UsingTask> 

    <PropertyGroup> 
    <MajorVersion>2</MajorVersion> 
    <MinorVersion>5</MinorVersion> 
    </PropertyGroup> 

    <Target Name="BeforeBuild"> 
    <Version BuildType="Automatic" RevisionType="Automatic" Major="$(MajorVersion)" Minor="$(MinorVersion)"> 
     <Output TaskParameter="Major" PropertyName="Major" /> 
     <Output TaskParameter="Minor" PropertyName="Minor" /> 
     <Output TaskParameter="Build" PropertyName="Build" /> 
     <Output TaskParameter="Revision" PropertyName="Revision" /> 
    </Version> 

    <FileUpdate Files="$(SolutionDir)SharedAssemblyInfo.vb" 
      Regex="Assembly: AssemblyVersion\(&quot;\d+\.\d+((\.\*)|(\.\d+\.\d+))?&quot;\)" 
      ReplacementText="Assembly: AssemblyVersion(&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" /> 

    <FileUpdate Files="$(SolutionDir)SharedAssemblyInfo.vb" 
      Regex="Assembly: AssemblyFileVersion\(&quot;\d+\.\d+((\.\*)|(\.\d+\.\d+))?&quot;\)" 
      ReplacementText="Assembly: AssemblyFileVersion(&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;)" /> 

    <SvnVersion LocalPath="."> 
     <Output TaskParameter="Revision" PropertyName="SvnRevision" /> 
    </SvnVersion> 

    <AddTextToImage InputPath="$(ProjectDir)Resources\Splash.png" 
        OutputPath="$(ProjectDir)Resources\SplashWithVersion.png" 
        TopMiddlePoint="250,150" 
        Text1="$(Major).$(Minor).$(Build).$(Revision)" 
        Text2="SVN Version: $(SvnRevision)" /> 

    <Message Text="Updated version number on splash screen to: $(Major).$(Minor).$(Build).$(Revision)" Importance="high"/> 
    </Target> 
</Project> 

이 당신의 어셈블리 정보와 출력 이미지를 업데이트합니다. Visual Studio에서 출력 이미지를 SplashScreen (빌드 작업)으로 표시해야합니다. 또한 내가 어셈블리 버전과 스플래시 화면에 SVN Revision 번호를 모두 쓰고 있음에 유의하십시오. 필요에 따라 조정할 수 있습니다.