none
Integrating FileTracker RRS feed

  • Question

  • Hello, I'm trying to create an MSBuild task that makes use of tracker.exe or FileTracker API or TrackedVCToolTask and integrates directly with Visual Studio so that Visual Studio reads the tlogs generated by this task to determine if the task can be skipped or not. It is my understanding, according to Inside the Microsoft Build engine: using MSBuild and Team Foundation Build that tlogs belong in the intermediate directory of the project you are building. I've opted using FileTracker API in a custom task that inherits from MSBuild's Task base class.

    I am able to produce tlogs through a custom task created through a C# dll that makes calls to the FileTracker API.

    I am unable to find a way for Visual Studio to use these tlogs in detecting whether or not to skip the custom target/task.

    I am aware of the simpler approach of using Input and Output TaskItem attributes but this approach is not what I'm looking for as it lacks the ability to automatically detect file dependencies.

    I've looked at many resources but all references I could find stop just short of explaining the process of implementing and integrating FileTracker's Api/TrackedVCToolTask/tracker.exe with Visual Studio.

    Looking forward to any help/resources that can be provided.









    • Edited by Devu42 Wednesday, October 9, 2019 6:43 AM
    Wednesday, October 9, 2019 6:07 AM

Answers

  • Hi Devu42,

    Welcome to the MSDN forum.

    According to your description, you generated tlogs by custom task, why should VS monitor these tlogs to determine if a custom method was skipped. You have invoked the custom method to generate tlogs, indicating that the custom task has been executed.

    How do you invoke custom methods, not by executing them on the command line, as we normally do with custom methods in developer command prompt,like:

    msbuild xxxx.csproj -t:Build,customTask

    If you want to build in VS IDE, you can add the this function  

    <Target Name="MyTask" AfterTargets="Build">
    
    .........
    
    </Target>

    >>You can refer to this document to customize the writing task for the function you are talking about.

    https://docs.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2019

    > > If it does not help or l misunderstand your issue, please tell us how you call this custom method, what features do you want to implement and any other useful information.

    Any feedback will be expected.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, October 9, 2019 9:31 AM
  • I appreciate all the help Perry. My current goal right now is simply to figure out how to implement TrackedVCToolTask. With that in my mind it would seem my best bet is to use .Net Reflector to look at the following proprietary Microsoft classes along with their accompanying xml files, As well as their comments that can be found through navigating to their assembly in Visual Studio.
    namespace Microsoft.Build.CPPTasks
    {
        class ClangCompile : TrackedVCToolTask     {         ...     }     class CL : TrackedVCToolTask     {         ...     }
    }
    If I figure out how to implement them I'll post what I find here for anyone looking for the same thing. There's nothing more I can think to ask; thanks for the help, cheers.




    • Marked as answer by Devu42 Friday, October 11, 2019 7:42 AM
    • Edited by Devu42 Friday, October 11, 2019 7:44 AM
    Friday, October 11, 2019 6:31 AM

All replies

  • Hi Devu42,

    Welcome to the MSDN forum.

    According to your description, you generated tlogs by custom task, why should VS monitor these tlogs to determine if a custom method was skipped. You have invoked the custom method to generate tlogs, indicating that the custom task has been executed.

    How do you invoke custom methods, not by executing them on the command line, as we normally do with custom methods in developer command prompt,like:

    msbuild xxxx.csproj -t:Build,customTask

    If you want to build in VS IDE, you can add the this function  

    <Target Name="MyTask" AfterTargets="Build">
    
    .........
    
    </Target>

    >>You can refer to this document to customize the writing task for the function you are talking about.

    https://docs.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2019

    > > If it does not help or l misunderstand your issue, please tell us how you call this custom method, what features do you want to implement and any other useful information.

    Any feedback will be expected.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, October 9, 2019 9:31 AM
  • Hi! thanks Perry. In my original post I was assuming VisualStudio used the tlog files automatically somehow. In retrospect, this would be impossible given that building dependencies with the tlog files requires internal knowledge of the custom tool. Thanks for clearing that up!

    To answer your question, I am trying to create a custom task that builds with the IDE and makes use of tlog files to track wether the custom task needs to run on one file or only a select few. I have a working proof of concept that consists of a custom target called via a compiled c# dll. Here is a snippet of working code that i have so far.

    <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\FooTask.dll" TaskName="FooTask" /> <Target Name="Demo"> <FooTask/> </Target> ...

      <PropertyGroup>
        <BuildDependsOn>
            Demo;
            $(BuildDependsOn);
        </BuildDependsOn>
      </PropertyGroup>

    </Project>

    
    More specifically, I was wondering if I could get any insights into how to implement the FileTracker API or TrackedVCToolTask in order to parse/build dependencies from .write and .read tlog files; As the process so far has been proving challenging to research.
     So far generating tlog files has proven to be extremely easy with the File Tracker API.
    (snippet from FooTask)
              FileTracker.StartProcess("FileTrackerTestAppCompanion.exe", "FilesToGenerate.txt", ExecutableType.Managed64Bit);
    I am stuck when it comes to using these tlog files to build a dependency table; For example, the following is a non-working code snippet that outlines what i'm attempting to do from within FooTask.

    var writeTLogs = new ITaskItem[] { new TaskItem(absoluteFilePathToReadTLogFile) }; var readTLogs = new ITaskItem[] { new TaskItem(absoluteFilePathToWriteTlogFile) }; var sourceFiles = new ITaskItem[] { new TaskItem(absoluteFilePathToFilesToGenerateFile) }; CanonicalTrackedOutputFiles canonicalTrackedOutputFiles = new CanonicalTrackedOutputFiles(writeTLogs); CanonicalTrackedInputFiles canonicalTrackedInputFiles = new CanonicalTrackedInputFiles(readTLogs, sourceFiles, canonicalTrackedOutputFiles, false, false);

              var sourcesNeedingCompilation = canonicalTrackedInputFiles.ComputeSourcesNeedingCompilation();






















    • Edited by Devu42 Thursday, October 10, 2019 8:26 AM
    Thursday, October 10, 2019 7:28 AM
  • Hi Devu42,

    How can you use tlogs to determine whether the custom method is executed, since you have invoked the custom method to generate tlogs before the project runs?

    Are you judging another custom task based on the information in the tlog? If you are judging another custom task based on the information in the tlog log, I recommend that you separate the task that generated the log from the task that judged the log.

    //generate the log <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\FooTask.dll" TaskName="Foo1Task" /> <Target Name="Demo1"> <FooTask/> </Target> //judge the cusomtask by log <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\FooTask.dll" TaskName="Foo2Task" /> <Target Name="Demo2" > <FooTask/> </Target>

    //the task before build, it will execute in sequence <PropertyGroup>
        <BuildDependsOn>
            Demo1;Demo2
            $(BuildDependsOn);
        </BuildDependsOn>
      </PropertyGroup>

    When you build ,it will execute Demo1 then Demo2 first.

    > >You can also use task1 to generate the log and task2 to get the judgment values in the log to do the specific trace or define a property in csproj, and task1 to generate the log and task2 to get the judgment values in the log to do the specific trace or operation.

    You can refer to this official document for more information.

    https://docs.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2019

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com



    Thursday, October 10, 2019 10:20 AM
  • I appreciate all the help Perry. My current goal right now is simply to figure out how to implement TrackedVCToolTask. With that in my mind it would seem my best bet is to use .Net Reflector to look at the following proprietary Microsoft classes along with their accompanying xml files, As well as their comments that can be found through navigating to their assembly in Visual Studio.
    namespace Microsoft.Build.CPPTasks
    {
        class ClangCompile : TrackedVCToolTask     {         ...     }     class CL : TrackedVCToolTask     {         ...     }
    }
    If I figure out how to implement them I'll post what I find here for anyone looking for the same thing. There's nothing more I can think to ask; thanks for the help, cheers.




    • Marked as answer by Devu42 Friday, October 11, 2019 7:42 AM
    • Edited by Devu42 Friday, October 11, 2019 7:44 AM
    Friday, October 11, 2019 6:31 AM