久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 AssemblyInfo 后編譯讀取 AssemblyFileVersion

Read AssemblyFileVersion from AssemblyInfo post-compile(從 AssemblyInfo 后編譯讀取 AssemblyFileVersion)
本文介紹了從 AssemblyInfo 后編譯讀取 AssemblyFileVersion的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

如何讀取 AssemblyFileVersion 或其組件 AssemblyFileMajorVersionAssemblyFileMinorVersionAssemblyFileBuildNumberAssemblyFileRevision,在 .csproj 中,編譯后?

How can one read the AssemblyFileVersion, or its components AssemblyFileMajorVersion, AssemblyFileMinorVersion, AssemblyFileBuildNumber, AssemblyFileRevision, within the .csproj, following compilation?

我嘗試了以下從構(gòu)建的程序集中提取信息的方法:

I have tried the following which pulls the information from the built assembly:

<Target Name="AfterCompile">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
         <Output
             TaskParameter="Assemblies"
             ItemName="MyAssemblyIdentities"/>
    </GetAssemblyIdentity>
    <Message Text="AssemblyVersion = %(MyAssemblyIdentities.Version)" />
</Target>

但這會檢索 AssemblyVersion 而不是 AssemblyFileVersion.后者似乎沒有記錄在案的元數(shù)據(jù)條目.我也試過了:

But that retrieves the AssemblyVersion and not the AssemblyFileVersion. There does not seem to be a documented metadata entry for the latter. I also tried:

<Import Project="$(MSBuildExtensionsPath)ExtensionPackMSBuild.ExtensionPack.tasks" />
<Target Name="AfterCompile">
    <MSBuild.ExtensionPack.Framework.Assembly TaskAction="GetInfo" NetAssembly="$(TargetPath)">
        <Output TaskParameter="OutputItems" ItemName="Info" />
    </MSBuild.ExtensionPack.Framework.Assembly>
    <Message Text="AssemblyFileVersion = %(Info.FileVersion)" />
</Target>

不幸的是,雖然這會檢索到正確的值,但它也會文件鎖定程序集,直到 VS2008 關(guān)閉.

Unfortunately, while this retrieves the correct value, it also file locks the assembly until VS2008 is closed.

坦率地說,這也不是我想要的,因?yàn)槲覍幵钢苯訌?AssemblyInfo.cs 中讀取信息.但是,我無法弄清楚如何做到這一點(diǎn).我認(rèn)為 MSBuild Extensions 中的 AssemblyInfo 是一種方式,但它似乎專注于寫入 AssemblyInfo 而不是從中檢索值.

Frankly, neither is what I want as I would rather read the information from the AssemblyInfo.cs directly. However, I cannot figure out how to do that. I assumed AssemblyInfo in the MSBuild Extensions was one way, but it seems focused on writing to the AssemblyInfo and not retrieving values from it.

我怎樣才能最好地做到這一點(diǎn)?

How can I best accomplish this?

推薦答案

我已經(jīng)設(shè)法使用自定義任務(wù)解決了這個問題.類庫 DLL 就是這樣(為簡潔起見調(diào)整/刪除了一些代碼):

I've managed to solve this using a custom task. The class library DLL is as so (some code adjusted/eliminated for brevity):

using System;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;

namespace GetAssemblyFileVersion
{
    public class GetAssemblyFileVersion : ITask
    {
        [Required]
        public string strFilePathAssemblyInfo { get; set; }
        [Output]
        public string strAssemblyFileVersion { get; set; }
        public bool Execute()
        {
            StreamReader streamreaderAssemblyInfo = null;
            Match matchVersion;
            Group groupVersion;
            string strLine;
            strAssemblyFileVersion = String.Empty;
            try
            {
                streamreaderAssemblyInfo = new StreamReader(strFilePathAssemblyInfo);
                while ((strLine = streamreaderAssemblyInfo.ReadLine()) != null)
                {
                    matchVersion = Regex.Match(strLine, @"(?:AssemblyFileVersion("")(?<ver>(d*).(d*)(.(d*)(.(d*))?)?)(?:""))", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
                    if (matchVersion.Success)
                    {
                        groupVersion = matchVersion.Groups["ver"];
                        if ((groupVersion.Success) && (!String.IsNullOrEmpty(groupVersion.Value)))
                        {
                            strAssemblyFileVersion = groupVersion.Value;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                BuildMessageEventArgs args = new BuildMessageEventArgs(e.Message, string.Empty, "GetAssemblyFileVersion", MessageImportance.High);
                BuildEngine.LogMessageEvent(args);
            }
            finally { if (streamreaderAssemblyInfo != null) streamreaderAssemblyInfo.Close(); } 
            return (true);
        }
        public IBuildEngine BuildEngine { get; set; }
        public ITaskHost HostObject { get; set; }
    }
}

并且在項(xiàng)目文件中:

<UsingTask AssemblyFile="GetAssemblyFileVersion.dll" TaskName="GetAssemblyFileVersion.GetAssemblyFileVersion" />
<Target Name="AfterCompile">
    <GetAssemblyFileVersion strFilePathAssemblyInfo="$(SolutionDir)AssemblyInfo.cs">
        <Output TaskParameter="strAssemblyFileVersion" PropertyName="strAssemblyFileVersion" />
    </GetAssemblyFileVersion>
    <Message Text="AssemblyFileVersion = $(strAssemblyFileVersion)" />
</Target>

我已經(jīng)對此進(jìn)行了測試,如果您使用 MSBuild.ExtensionPack.VersionNumber.targets 進(jìn)行自動版本控制,它將讀取更新的版本.

I've tested this and it will read the updated version if you use MSBuild.ExtensionPack.VersionNumber.targets for auto-versioning.

顯然,這可以很容易地?cái)U(kuò)展,以便將正則表達(dá)式從項(xiàng)目文件傳遞到更通用的自定義任務(wù),以獲得任何文件中的任何匹配.


2009/09/03 更新:

Obviously, this could be easily extended so that a regex is passed from the project file to a more general-purpose custom task in order to obtain any match in any file.


Update 2009/09/03:

必須進(jìn)行一項(xiàng)額外的更改才能在每次構(gòu)建時更新 ApplicationVersion.InitialTargets="AfterCompile" 必須添加到 <Project....這是郭超解決的.

One additional change has to be made to make the ApplicationVersion update on each build. InitialTargets="AfterCompile" must be added to the <Project.... This was solved by Chao Kuo.

這篇關(guān)于從 AssemblyInfo 后編譯讀取 AssemblyFileVersion的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網(wǎng)站添加了書簽?)
Use of Different .Net Languages?(使用不同的 .Net 語言?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點(diǎn)的“活動用戶數(shù))
Best way to keep track of current online users(跟蹤當(dāng)前在線用戶的最佳方式)
Recommend an Open Source .NET Statistics Library(推薦一個開源的.NET統(tǒng)計(jì)庫)
Create a summary description of a schedule given a list of shifts(給定輪班列表,創(chuàng)建時間表的摘要描述)
主站蜘蛛池模板: 国产精品1区2区3区 中文字幕一区二区三区四区 | 久久精品视频网站 | 国产一区视频在线 | 亚洲视频一区二区三区 | 欧美成人在线网站 | 亚洲精品久久久蜜桃网站 | 激情欧美一区二区三区中文字幕 | 国产精品色av | 久久国产精品久久久久久 | 欧美国产日本一区 | 精品国产乱码久久久久久丨区2区 | 亚洲精品第一国产综合野 | 日韩中文字幕 | 在线国产小视频 | 岛国视频 | 亚洲日韩中文字幕一区 | 97视频在线观看网站 | 欧美一级视频在线观看 | 欧美激情精品久久久久久免费 | 欧美一区二区三区在线 | 久久久影院 | 91麻豆蜜桃一区二区三区 | 中文字幕在线不卡播放 | 国产精品久久久久久久久久 | 国产精品视频免费观看 | 亚洲一区在线观看视频 | 成人激情视频在线观看 | 欧美一级二级视频 | 色眯眯视频在线观看 | 男女精品网站 | 亚洲欧美另类在线 | 黄色国产大片 | 欧美日韩视频 | 欧美视频免费在线 | 日韩免费视频 | 精品二区| 国产日韩精品视频 | 国产免费福利小视频 | 神马影院一区二区三区 | 日本人麻豆 | 黄色网址在线免费观看 |