{"id":18021264,"url":"https://github.com/ho-cooh/msbuild-inline-task-demo","last_synced_at":"2026-05-08T01:49:21.649Z","repository":{"id":200351432,"uuid":"705329570","full_name":"HO-COOH/MsBuild-Inline-Task-Demo","owner":"HO-COOH","description":"A demo about running C# code in msbuild","archived":false,"fork":false,"pushed_at":"2023-10-16T18:18:58.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T02:45:30.316Z","etag":null,"topics":["csharp","csproj","dotnet","msbuild","nuget","vcxproj","visual-studio"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HO-COOH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-15T18:02:29.000Z","updated_at":"2024-04-17T17:34:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"2485b845-f4f6-418c-82db-c03b422f571e","html_url":"https://github.com/HO-COOH/MsBuild-Inline-Task-Demo","commit_stats":null,"previous_names":["ho-cooh/msbuild-inline-task-demo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HO-COOH%2FMsBuild-Inline-Task-Demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HO-COOH%2FMsBuild-Inline-Task-Demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HO-COOH%2FMsBuild-Inline-Task-Demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HO-COOH%2FMsBuild-Inline-Task-Demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HO-COOH","download_url":"https://codeload.github.com/HO-COOH/MsBuild-Inline-Task-Demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217878,"owners_count":20903155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csproj","dotnet","msbuild","nuget","vcxproj","visual-studio"],"created_at":"2024-10-30T06:09:15.843Z","updated_at":"2026-05-08T01:49:16.629Z","avatar_url":"https://github.com/HO-COOH.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MSBuild Inline Task demo\nThis demo shows how to display a WPF window using `MSBuild` files only.\nThe real usage is to modify stuff with C# code during build process, which you can utilize from a nuget library that you automatically modify something in the consuming project after installing it.\n\n## How?\n### Using directly in build file (`csproj` / `vcxproj`)\n- Define a `UsingTask` to a `.targets` or `.vcxproj` or `.csproj` file\n```xml\n\u003c!--TaskName be your arbitary name--\u003e\n\u003cUsingTask TaskName=\"HelloWorld\" TaskFactory=\"RoslynCodeTaskFactory\" AssemblyFile=\"$(MSBuildToolsPath)\\Microsoft.Build.Tasks.Core.dll\"\u003e\n    \u003cParameterGroup\u003e\n        \u003c!--Add parameters here--\u003e\n    \u003c/ParameterGroup\u003e\n    \u003cTask\u003e\n        \u003c!--Add assembly reference here--\u003e\n        \u003cReference Include=\"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\PresentationFramework.dll\"/\u003e\n        \n        \u003c!--Using Namespaces here--\u003e\n        \u003cUsing Namespace=\"System.Windows\"/\u003e\n\n        \u003cCode Type=\"Fragment\" Language=\"cs\"\u003e\u003c![CDATA[\n            //Your C# code here.\n            //Actually all code here are inside a function, which you can see from the msbuild output temporary file\n            //So you can't define struct or classes.\n            //You can only define static functions here.\n        ]]\u003e\u003c/Code\u003e\n    \u003c/Task\u003e\n\u003c/UsingTask\u003e\n\n\u003cTarget Name=\"Demo\"\u003e \u003c!--Reference this target name in the \"PropertyGroup\" below--\u003e\n    \u003cHelloWorld/\u003e  \u003c!--Your arbitary name--\u003e\n\u003c/Target\u003e\n```\n- Add a `\u003cPropertyGroup\u003e` in that same file, and the thing inside it **varies** depending on your project type, if it's a C++ project (`.vcxproj` file), the following code execute the code **before** builds.\n```xml\n\u003cPropertyGroup\u003e\n    \u003cBeforeMidlCompileTargets\u003e\n        $(BeforeMidlCompileTargets);\n        Demo  \u003c!--Your \"Target\" name above--\u003e\n    \u003c/BeforeMidlCompileTargets\u003e\n\u003c/PropertyGroup\u003e\n```\n### Using with `.targets` file\nJust add a `\u003cImport Project=\"\u003cYour .targets file\u003e\" /\u003e` node as a child of the `\u003cImportGroup Label=\"ExtensionTargets\"\u003e` (which will be automatically added if there is one in your nuget package).\n```xml\n\u003cImportGroup Label=\"ExtensionTargets\"\u003e\n    \u003cImport Project=\"Me.targets\"/\u003e\n\u003c/ImportGroup\u003e\n```\n\n## Result\nOpen a `Developer Powershell`, run `msbuild.exe`, and you shall see this.\n![image](https://github.com/HO-COOH/MsBuild-Inline-Task-Demo/assets/42881734/bf728bc8-b6a7-45b0-b452-94601f7be8e6)\n\n## More info\n- [msbuild file schema](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-project-file-schema-reference?view=vs-2022)\n- [The very hard to find msbuild api doc](https://learn.microsoft.com/en-us/dotnet/api/?view=msbuild-17-netcore)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fho-cooh%2Fmsbuild-inline-task-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fho-cooh%2Fmsbuild-inline-task-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fho-cooh%2Fmsbuild-inline-task-demo/lists"}