Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ho-cooh/msbuild-inline-task-demo

A demo about running C# code in msbuild
https://github.com/ho-cooh/msbuild-inline-task-demo

csharp csproj dotnet msbuild nuget vcxproj visual-studio

Last synced: about 2 months ago
JSON representation

A demo about running C# code in msbuild

Awesome Lists containing this project

README

        

# MSBuild Inline Task demo
This demo shows how to display a WPF window using `MSBuild` files only.
The 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.

## How?
### Using directly in build file (`csproj` / `vcxproj`)
- Define a `UsingTask` to a `.targets` or `.vcxproj` or `.csproj` file
```xml











```
- Add a `` 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.
```xml


$(BeforeMidlCompileTargets);
Demo

```
### Using with `.targets` file
Just add a `` node as a child of the `` (which will be automatically added if there is one in your nuget package).
```xml

```

## Result
Open a `Developer Powershell`, run `msbuild.exe`, and you shall see this.
![image](https://github.com/HO-COOH/MsBuild-Inline-Task-Demo/assets/42881734/bf728bc8-b6a7-45b0-b452-94601f7be8e6)

## More info
- [msbuild file schema](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-project-file-schema-reference?view=vs-2022)
- [The very hard to find msbuild api doc](https://learn.microsoft.com/en-us/dotnet/api/?view=msbuild-17-netcore)