Question

Avinash Sembhoo on Tue, 15 Jul 2014 07:00:01


Please bear with me since I'm still new to MSBuild; Actually i was trying to use the MSBuild task to compile a list of .Net project files. I wanted to have a log of the list of project files that were compiled successfully, a list of those which were skipped due to not having any new changes checked into TFS and finally a list of those projects which failed to compile.

I tried a few options after looking at a few code snippets on the net but am still not able to get the logs populated correctly.
Please find below the sample project file that i am using:

<Target Name="CoreBuild">
           <MSBuild Projects="@(ProjectsToBuild)"
                                        ContinueOnError="true"
                                        Properties="OutputPath=D:\Projects\bin-dotnet\;
                                        OutDir=D:\Projects\bin-dotnet\;
                                        Configuration=Debug;
                                        DefineTrace=true;
                                        SkipUnchanged=true;">
                         <Output TaskParameter="TargetOutputs" ItemName="CompiledAssemblies" />
                         <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
            </MSBuild>
</Target>

<ItemGroup>
    <DotNetRecompileLog Include="D:\Projects\Dot_Net_Compile_Log.log"/>
    <DotNetSkippedLog Include="D:\Projects\Dot_Net_Skipped_Log.log"/>
    <DotNetFailedLog Include="D:\Projects\Dot_Net_Failed_Log.log"/>
   
    <CompiledProjects Include="@(ProjectsToBuild)"/>
    <SkippedProjects Include="@(ProjectsToBuild)"/>
    <FailedProjects Include="@(ProjectsToBuild)"/>
</ItemGroup>
 
<Target Name="WriteLogs">
    <WriteLinesToFile File="@(DotNetRecompileLog)" Lines="@(CompiledProjects)" Overwrite="true" Encoding="UTF-8" />
    <WriteLinesToFile File="@(DotNetSkippedLog)" Lines="@(SkippedProjects)" Overwrite="true" Encoding="UTF-8" />
    <WriteLinesToFile File="@(DotNetFailedLog)" Lines="@(FailedProjects)" Overwrite="true" Encoding="UTF-8" />
</Target> 

Basically i am trying to get the list of:

             1. Successfully recompiled projects into D:\Projects\Dot_Net_Compile_Log.log

             2. Skipped projects into D:\Projects\Dot_Net_Skipped_Log.log

             3. Failed projects into D:\Projects\Dot_Net_Failed_Log.log

For the time being, it's just flushing out the complete list of projects into all 3 logs. Can anyone please help me find a way of doing that?

Replies

Anna Cc on Wed, 16 Jul 2014 03:02:31


Hi,

>> a list of those which were skipped due to not having any new changes checked into TFS and finally a list of those projects which failed to compile.

You can make the files that haven't been changed are built when build the project by setting the option "clean workspace". In TFS 2012, the value is "All" and in TFS 2013, the value is "True".

Best regards,

Avinash Sembhoo on Wed, 16 Jul 2014 14:27:47


Hi Pactera,

Thanks for showing interest in replying to my post.

In fact i am passing in a list of .NET projects to be compiled. And out of these projects not all of them would be compiled. Maybe some would be skipped, some may fail to compile due to maybe some errors in the code.

So basically i want to have 3 log files each containing the list of projects as follows:

Failed_Log => List projects that failed to compile successfully

Skipped_Log => List projects that were skipped since maybe code was not changed

Compile_Log => List projects that were compiled

I need these 3 logs.

Anna Cc on Thu, 17 Jul 2014 08:55:16


Hi,

Thank you for your feedback!

I'm still not clear that a project hasn't been changed that been build skipped then it lead to build fail.

Generally, when we build a large project, it is important that previously built components that are still up-to-date are not rebuilt. If all targets are built every time, each build will take a long time to complete. So I'm confused why it fails.

Also, I feel a little chaos of the ItemGroup tag and the WriteLogs target.

<CompiledProjects Include="@(ProjectsToBuild)"/>
<SkippedProjects Include="@(ProjectsToBuild)"/>
<FailedProjects Include="@(ProjectsToBuild)"/>

All the CompiledProjects, SkippedProjects and FailedProjects items include all the project to build. And you write the same build projects to the 3 log files. So the complete list of projects into all 3 logs. Because I have no the solution with projects skipped, please share me with a sample project to reproduce this issue. If I have any misunderstanding, please feel free to point out.

Best regards,


We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.





Avinash Sembhoo on Mon, 21 Jul 2014 09:26:48


Please find below the command lines regarding the projects compilation. I have created 5 projects:

    1. Project1.vbproj (Skipped due to no code changes)

    2. Project2.vbproj (Added lines to project files to make it to fail during compilation)

    3. Project3.vbproj (Skipped due to no code changes)

    4. Project4.vbproj (Added new code changes to make sure project gets picked up and recompiled)

    5. Project5.vbproj (Skipped due to no code changes)

Currently all the 3 logs would contain the list of all projects; however i wanted to change it to get the project lists filtered based on the compiled status. I don't have any idea how to do that.

Folllowing that, I wanted to have the following in the different output logs:

Compile Log:

               C:\Projects\Project4\Project4\Project4.vbproj

Skipped Log:

               C:\Projects\Project1\Project1\Project1.vbproj

               C:\Projects\Project3\Project3\Project3.vbproj

               C:\Projects\Project5\Project5\Project5.vbproj

Failed Log:

               C:\Projects\Project2\Project2\Project2.vbproj

My codes are as follows:

<Project DefaultTargets="CompileLibraries" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    <Import Project="C:\Program Files (x86)\MSBuild\4.0\MSBuild.ExtensionPack.tasks"/>

            <ItemGroup>
                      <ProjectsToBuild Include="C:\Projects\Project1\Project1\Project1.vbproj"/>
                      <ProjectsToBuild Include="C:\Projects\Project2\Project2\Project2.vbproj"/>
                      <ProjectsToBuild Include="C:\Projects\Project3\Project3\Project3.vbproj"/>
                      <ProjectsToBuild Include="C:\Projects\Project4\Project4\Project4.vbproj"/>
                      <ProjectsToBuild Include="C:\Projects\Project5\Project5\Project5.vbproj"/>  
            </ItemGroup>
 
            <ItemGroup>   
                      <DLL_List Include="C:\Projects\bin-dotnet\Project1.dll"/>
                      <DLL_List Include="C:\Projects\bin-dotnet\Project2.dll"/>
                      <DLL_List Include="C:\Projects\bin-dotnet\Project3.dll"/>
                      <DLL_List Include="C:\Projects\bin-dotnet\Project4.dll"/>
                      <DLL_List Include="C:\Projects\bin-dotnet\Project5.dll"/>
            </ItemGroup>

            <PropertyGroup>
                      <CompileDependsOn>CoreBuild;WriteLogs</CompileDependsOn>
                      <WorkingDirectory>C:\Projects\bin-dotnet\</WorkingDirectory>
                      <OutputPath>C:\Projects\bin-dotnet\</OutputPath>
                      <OutDir>C:\Projects\bin-dotnet\</OutDir>
                      <Configuration>Debug</Configuration>
            </PropertyGroup>

            <Target Name="CompileLibraries" DependsOnTargets="$(CompileDependsOn)"/>

           <Target Name="CoreBuild">
                      <MSBuild Projects="@(ProjectsToBuild)" 
                                                    ContinueOnError="true"
                                                    Properties="OutputPath=C:\Projects\bin-dotnet\;
                                                    OutDir=C:\Projects\bin-dotnet\;
                                                    Configuration=Debug;
                                                    DefineTrace=true;
                                                    SkipUnchanged=false">
                              <Output TaskParameter="TargetOutputs" ItemName="CompiledAssemblies" />
                              <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
                       </MSBuild>
            </Target>

            <ItemGroup>
                      <DotNetRecompileLog Include="C:\Projects\Dot_Net_Compile_Log.log"/>
                      <DotNetSkippedLog Include="C:\Projects\Dot_Net_Skipped_Log.log"/>
                      <DotNetFailedLog Include="C:\Projects\Dot_Net_Failed_Log.log"/>
   
                      <CompiledProjects Include="@(ProjectsToBuild)"/>
                      <SkippedProjects Include="@(ProjectsToBuild)"/>
                      <FailedProjects Include="@(ProjectsToBuild)"/>
             </ItemGroup>
 
             <Target Name="WriteLogs">
                       <WriteLinesToFile File="@(DotNetRecompileLog)" Lines="@(CompiledProjects)"        Overwrite="true" Encoding="UTF-8" />
                       <WriteLinesToFile File="@(DotNetSkippedLog)" Lines="@(SkippedProjects)" Overwrite="true" Encoding="UTF-8" />
                       <WriteLinesToFile File="@(DotNetFailedLog)" Lines="@(FailedProjects)" Overwrite="true" Encoding="UTF-8" />
              </Target> 
</Project>

Avinash Sembhoo on Tue, 16 Sep 2014 07:21:44


Can someone please provide some directions/solution on how i can get the list of .NET projects compiled/failed/skipped using msbuild?