MSBuild: handling built-in tasks

I am working with MSBuild (version v4.0.30319 - 32-bit version) on Windows 2008 x64. I wanted to understand how MSBuild manages built-in tasks. Will it compile once per task call? Or will it compile once and reuse for each task call?

I started MSBuild with the argument "/ m" and tried to introduce a deliberate error into the C # code. And MSBuild pointed me to 1 text file (under the temp folder somewhere in my profile folder). No other text file has been created. However, I did not know how to understand this if there were no errors.

My intention is to try to understand this: To find out if it will be effective for the same order as the compiled dll (instead of the built-in task). The minimum overhead for compiling the embedded task code is acceptable if the compilation is performed only once (because I will save on the SCM aspects of the code and binary files).

<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="default" ToolsVersion="4.0"> <Target Name="default"> <ItemGroup> <A Include="1;2;3;4;5;6;7;8;9;10"/> </ItemGroup> <MSBuild Projects="$(MSBuildProjectFullPath)" BuildInParallel="true" Targets="Echoer" ToolsVersion="4.0" StopOnFirstFailure="true" Properties="Prop=%(A.Identity)"/> </Target> <Target Name="Echoer"> <MyTask WhatToEcho="$(Prop)"/> </Target> <UsingTask TaskName="MyTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> <ParameterGroup> <WhatToEcho ParameterType="System.String" Required="True"/> </ParameterGroup> <Task> <Code Language="cs" Type="Fragment"> <![CDATA[ Log.LogMessage("Property received: "+WhatToEcho); ]]> </Code> </Task> </UsingTask> </Project> 
+4
source share
1 answer

Running your example in ProcMon on my machine with MSBuild 4.5 shows the following:

  • A temporary assembly is created by MSBuild once for assembly in the user folder% TEMP%. (It was actually csc.exe that created the assembly, but I think this is just a side effect of how the code is generated).
  • The source code was in a temporary .cs file, also in% TEMP%.
  • By the end of the assembly, all files (source files as well as output assemblies) are deleted.

In other words, you will see the initial attack when you first call the task during assembly. All subsequent task calls will use the cached assembly. After the assembly, the cache is lost, the assembly must be recreated again, which means that if, after a quick incremental assembly, you can use a precompiled DLL.

+3
source

Source: https://habr.com/ru/post/1496330/


All Articles