首页 文章

如何在Visual Studio Team Services成功构建时标记源代码

提问于
浏览
9

我试图在Visual Studio Team Services(而不是XAML)上使用新的Build,但是在成功构建时无法弄清楚如何标记源代码 . 任何的想法?

下面的屏幕截图显示了如何在XAML中进行操作 .

enter image description here

我已经拥有https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/9613014-allow-label-source-upon-succesful-build-on-visual功能要求,我其实是问解决方法,直到Microsoft实现它 .

5 回答

  • 15

    标签源功能在vNext构建中不可用 .

    除标签源功能外,“关联工作项”和“构建失败时创建工作项”功能也不可用 .

    您可以在Microsoft UserVoice站点上提交有关它的一个功能请求:https://visualstudio.uservoice.com/forums/121579-visual-studio/category/30925-team-foundation-server-visual-studio-online

  • 13

    我刚刚注意到该功能现在可以在build vNext中使用 . 其配置位于构建定义的“存储库”选项卡中 .

    Labeling

  • 3

    我认为Yves Dierick的答案在2015年10月是正确的,但自那时起VSTS屏幕的布局发生了很大变化 . 在最新版本(截至2017年2月)中,您可以通过在“构建定义”中选择“获取源”任务,在右上角选择“显示高级设置”,然后选择“成功时”单选按钮,为成功构建添加标签 . 出现的标记源部分 .

    花了一段时间找到它,所以我认为它可能会帮助别人 . 这个选项在“标记源”下没有任何帮助,并且根本没有提到“标签”这个词 .

    enter image description here


    更新13/03/2018

    他们再次调整了这个页面的布局,但是如果有的话,它会变得更简单,现在这个选项更有用了"Label Sources" .
    Updated option for labelling builds

  • 1

    对于那些在这个线程中寻找TFS托管解决方案(而不是VSO)的人,请注意TFS 2015 Update 1中对构建标签的支持:https://www.visualstudio.com/en-us/news/tfs2015-update1-vs.aspx

    我们还没有运行Update 1,所以我无法确认 .

    编辑:我们现在正在运行Update 1(实际上是2),标签构建源适用于本地 .

  • 0

    XAML构建在构建开始时标记了源代码,而vNext构建似乎在构建结束时标记 . 我注意到了,因为我在构建期间修改/签入/标记文件 . 如果我让vNext标记构建,它会在签入之后将我应用的文件标签移动到以前的版本(GetSources中使用的版本) .

    但我没有在任何日志文件中看到vNext的标签 . 我错过了吗?我将不得不在vnext中禁用标签并在我的msbuild脚本中执行此操作...

    编辑:在vnext构建定义中禁用标记,并创建msbuild内联任务以标记工作区的源 . 现在我可以在构建开始时标记所有源代码并移动构建期间修改的文件的标签:)

    如果有人想做类似的事情,这是我的内联任务:

    <!--
        TaskName="LabelWorkspaceSources"
        - input: TfexeFullPath is the path to tf.exe
        - input: BaseDirectory is the mapped folder of the software to build
        - input: Label to apply
        - input: Version is the changeset to apply the label to
    -->
    <UsingTask TaskName="LabelWorkspaceSources" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
        <ParameterGroup>
            <TfexeFullPath Required="true" />
            <BaseDirectory Required="true" />
            <Label Required="true" />
            <Version Required="true" />
        </ParameterGroup>
        <Task>
            <Code Type="Fragment" Language="cs">
            <![CDATA[
    
            //--- get the workspace mapping ---
    
            System.Diagnostics.Process tfProcess = new System.Diagnostics.Process();
            tfProcess.StartInfo.FileName = TfexeFullPath;
            tfProcess.StartInfo.Arguments = "workfold";
            tfProcess.StartInfo.UseShellExecute = false;
            tfProcess.StartInfo.CreateNoWindow = true;
            tfProcess.StartInfo.RedirectStandardOutput = true;
            tfProcess.StartInfo.WorkingDirectory = BaseDirectory;
            tfProcess.Start();
    
            string output = tfProcess.StandardOutput.ReadToEnd();
    
            tfProcess.WaitForExit();
    
            string workfoldOutput = output.Trim();
            Log.LogMessage(workfoldOutput, MessageImportance.High);
    
            string[] linesWorkfoldOutput = workfoldOutput.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            List<string> mappedFolders = new List<string>();
    
            Log.LogMessage("Trying to parse mapped folders.", MessageImportance.High);
            foreach (string line in linesWorkfoldOutput)
            {
                //e.g. $/TPA: C:\TFS_Source\TPA
                if (line.Contains("$/"))
                {
                    string[] lineSplit = line.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries);
    
                    //entry lineSplit[0] now contains the server path, lineSplit[1] contains the local folder
                    mappedFolders.Add(lineSplit[1]);
                    Log.LogMessage("Found mapped folder: " + lineSplit[1], MessageImportance.High);
                }
            }
    
    
            //--- label all the mapped folders ---
    
            foreach (string mappedFolder in mappedFolders)
            {
                tfProcess = new System.Diagnostics.Process();
                tfProcess.StartInfo.FileName = TfexeFullPath;
                tfProcess.StartInfo.Arguments = "label " + Label + " \"" + mappedFolder + "\" /child:replace /recursive /comment:\"Label created by task LabelWorkspaceSources\" /version:" + Version;
                tfProcess.StartInfo.UseShellExecute = false;
                tfProcess.StartInfo.CreateNoWindow = true;
                tfProcess.StartInfo.RedirectStandardOutput = true;
                tfProcess.StartInfo.WorkingDirectory = mappedFolder;
                tfProcess.Start();
    
                output = tfProcess.StandardOutput.ReadToEnd();
    
                tfProcess.WaitForExit();
    
                Log.LogMessage(tfProcess.StartInfo.Arguments, MessageImportance.High);
                Log.LogMessage(output, MessageImportance.High);
            }
            ]]>
            </Code>
        </Task>
    </UsingTask>
    

相关问题