From 1f51b4f4da0c7f6d12ef111e457a69fca2d00956 Mon Sep 17 00:00:00 2001 From: Jack Liu Shurui Date: Wed, 3 Jul 2024 18:27:29 +0800 Subject: [PATCH] msbuild custom tasks --- .../posts/2024/06/msbuild-custom-task.adoc | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 content/posts/2024/06/msbuild-custom-task.adoc diff --git a/content/posts/2024/06/msbuild-custom-task.adoc b/content/posts/2024/06/msbuild-custom-task.adoc new file mode 100644 index 00000000..ab1d066c --- /dev/null +++ b/content/posts/2024/06/msbuild-custom-task.adoc @@ -0,0 +1,44 @@ +--- +title: msbuild custom task and runtime reflection +date: 2024-06-30T20:10:00+08:00 +categories: +- tech +tags: +- dotnet +- msbuild +- mono.cecil +--- + +Most information about custom task of msbuild are quite basic, it will get complicated when it is involved reflection. +I tried several ways according searching results and answers from chatgpt: reflection, assemblyLoadContext and mono cecil. The most promising one is **mono.cecil**. + +I tried directly loading assemblies and via AssemblyLoadContext. They all failed to load some microsoft assemblies. It looks awkward even I can change my build scripts to copy those assemblies. +Thought of several discussion threads and several open source libraries mentioned in the thread, They all adopt other ways to do that. I only found mono.cecil has a business friendly license term (MIT). + +During testing my custom task, the following two commands are helpful to get the logs. + +[source, batch] +---- +dotnet build -v:n +dotnet build -v:d +---- + +Message task is helpful to show properties in logs. + +[source, xml] +---- + + + + + + +---- + +Another way to develop and debug fastly: + +. Add System.Diagnostics.Debugger.Launch() in code. +. Build debug version, pack, add to local feed, and use that package +. Copy any changes (ddl, props, targets) to %userprofile%/packages/[your package]/[versionid] \ No newline at end of file