Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 在正在运行的应用程序中获取TFS变更集_Visual Studio_Tfs_Msbuild - Fatal编程技术网

Visual studio 在正在运行的应用程序中获取TFS变更集

Visual studio 在正在运行的应用程序中获取TFS变更集,visual-studio,tfs,msbuild,Visual Studio,Tfs,Msbuild,我已经在网上搜索了大约2天了。也许我没有使用正确的术语。我希望用当前的TFS变更集varriable编译我的项目。我没有使用TFS构建 我尝试过的唯一一件事没有成功,就是使用MSBuild任务获取当前变更集(而不仅仅是)并将其放入程序集版本(修订版)。它失败了,因为我没有使用生成 这是我第一次使用这种“任务”类型的编程,我不知道在不设置TFS版本的情况下是否可以做到这一点。我无法设置版本,因为我使用外部DLL和项目,安装起来似乎很复杂。 (我的下一步是检查更多关于TFS构建的信息) 我之所以在运

我已经在网上搜索了大约2天了。也许我没有使用正确的术语。我希望用当前的TFS变更集varriable编译我的项目。我没有使用TFS构建

我尝试过的唯一一件事没有成功,就是使用MSBuild任务获取当前变更集(而不仅仅是)并将其放入程序集版本(修订版)。它失败了,因为我没有使用生成

这是我第一次使用这种“任务”类型的编程,我不知道在不设置TFS版本的情况下是否可以做到这一点。我无法设置版本,因为我使用外部DLL和项目,安装起来似乎很复杂。 (我的下一步是检查更多关于TFS构建的信息)

我之所以在运行时需要这个值,是因为我在错误报告功能中需要这个值。我希望使这个过程自动化以避免错误

(Visual studio 2013,TFS[VisualStudio.com],Asp.net MVC 5)

解决方案: 给朱利奥·维安的坦克

这将获取当前解决方案的TFS变更集,而不是最新的,并将其写入文件“TFS.cs”。 输出文件如下所示:

static class TFS { public static string ChangeSet { get { return "436"; }}} 
我已在项目的根目录中创建了一个文件“TFS.targets”:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- 
    add this line to Target to run this only on Release:
    Condition="'$(Configuration)' == 'Release'" -->
  <Target Name="BeforeBuild" > 

    <!-- Get information on the latest build -->
    <Message Importance="High" Text="Getting TFS Chanset"/>
    <Exec Command="&quot;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe&quot; info &quot;$(SolutionPath)&quot; | FIND &quot;Changeset&quot;" ConsoleToMSBuild="true">
      <Output TaskParameter="ConsoleOutput" PropertyName="ChangesetLine" />
    </Exec>
    <PropertyGroup>
      <ChangesetNumber>$(ChangesetLine.Substring(13, $([MSBuild]::Subtract( $(ChangesetLine.IndexOf(';')) , 13 ))))</ChangesetNumber>
    </PropertyGroup>

    <Message Importance="High" Text="ChangeSet: '$(ChangesetNumber)'. Writing TFS.cs ..."/>
    <Exec Command="echo static class TFS { public static string ChangeSet { get { return &quot;$(ChangesetNumber)&quot;; }}} &gt; TFS.cs" Outputs="TFS.cs">
      <!--Add this file to the list to compile-->
      <!--<Output ItemName="Compile" TaskParameter="Outputs" />-->
    </Exec>
  </Target>
</Project>
问题是它会给您一个很难用MsBuild提取的响应

我编写了一个控制台应用程序,它只返回变更集:

static void Main(string[] args)
        {

            Process p = new Process();
            // Redirect the output stream of the child process.
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe";
            p.StartInfo.Arguments = "history \"" + args[0] + "\" /noprompt /recursive /stopafter:1";
            p.Start();
            // Do not wait for the child process to exit before
            // reading to the end of its redirected stream.
            // p.WaitForExit();
            // Read the output stream first and then wait.
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            var lines = output.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var last = lines.Last();
            var s = last.Split(' ');
            Console.WriteLine(s[0]);

        }
该任务只能检索TFS生成的更改集。您说您还没有使用TFS生成,因此无法使用

您可以使用从TFS中提取变更集

老实说,如果你打算这样做的话,那么这比仅仅使用TFS构建系统要困难得多。

该任务只能检索TFS构建的变更集。你说你还没有使用TFS构建,所以这不起作用

您可以使用从TFS中提取变更集


老实说,如果你打算使用TFS构建系统,那么这比使用TFS构建系统要困难得多。

你可以调用
tf
命令来获取有关TFVC文件和文件夹的信息。通过在映射到工作区的本地目录中运行
tf info
命令,你可以获得很多有用的数据,例如。

本地信息:
本地路径:D:\Workspaces\xyz\mine.sln
服务器路径:$/DefaultCollection/xyz/mine.sln
变更集:6611
更改:无
类型:文件
服务器信息:
服务器路径:$/DefaultCollection/xyz/mine.sln
变更集:6611
删除ID:0
锁:没有
锁所有者:
最后修改:2015年3月14日星期六09:38:44
类型:文件
文件类型:utf-8
规模:1994年

在MSBuild文件中嵌入该命令并不难,如以下代码段所示

$(ChangesetLine.Substring(13,$([MSBuild]::减法($(ChangesetLine.IndexOf(';')),13)))


tf
命令随团队资源管理器一起安装。

您可以调用
tf
命令来获取有关TFVC文件和文件夹的信息。通过在映射到工作区的本地目录中运行
tf info
命令,您可以获得许多有用的数据,例如。

本地信息:
本地路径:D:\Workspaces\xyz\mine.sln
服务器路径:$/DefaultCollection/xyz/mine.sln
变更集:6611
更改:无
类型:文件
服务器信息:
服务器路径:$/DefaultCollection/xyz/mine.sln
变更集:6611
删除ID:0
锁:没有
锁所有者:
最后修改:2015年3月14日星期六09:38:44
类型:文件
文件类型:utf-8
规模:1994年

在MSBuild文件中嵌入该命令并不难,如以下代码段所示

$(ChangesetLine.Substring(13,$([MSBuild]::减法($(ChangesetLine.IndexOf(';')),13)))


tf
命令随团队资源管理器一起安装。

构建的当前过程是什么?使用哪个工具?设置构建服务器可能比编写自己的构建系统简单。构建的当前过程是什么?使用哪个工具?设置构建服务器可能比编写您的构建系统简单r自己的构建系统。Ho tanks!我会试试这个。我如何在c#中获取这个ChangesetNumber?我已经尝试过了,但我得到了这个错误:“命令”tf info“| FIND”Changeset“退出,代码为255”这正常吗?我不能在命令提示符中使用它?(命令未找到)正如我所说,TF命令在安装团队资源管理器后可用;可能是因为它没有列在路径中,请尝试使用完整路径,例如C:\Program Files(x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exeHo tanks!我将尝试此操作。我如何在C#中获取此ChangesetNumber?我已经尝试过了,但出现以下错误:'the command“TF info”“| FIND”变更集“”已退出,代码为255是否正常我无法在命令提示符中使用此命令?(未找到命令)正如我所说,TF命令在安装团队资源管理器后可用;可能是它未列在路径中,请尝试使用完整路径,例如C:\Program Files(x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe
tf history "c:\YourSolutionDir" /noprompt /recursive /stopafter:1
static void Main(string[] args)
        {

            Process p = new Process();
            // Redirect the output stream of the child process.
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe";
            p.StartInfo.Arguments = "history \"" + args[0] + "\" /noprompt /recursive /stopafter:1";
            p.Start();
            // Do not wait for the child process to exit before
            // reading to the end of its redirected stream.
            // p.WaitForExit();
            // Read the output stream first and then wait.
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            var lines = output.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var last = lines.Last();
            var s = last.Split(' ');
            Console.WriteLine(s[0]);

        }