C
C#5mo ago
ascpixi

✅ Evaluating arbitrary XML in MSBuild?

Hi all! :cathi: Is there any way to evaluate some arbitrary XML in MSBuild - similarly to how you'd do it with <Import>, just without the need for a file? My use case is that I want to call into a script, e.g. python supply-props.py, which will supply dynamically-generated properties, targets, etc., based on a more sane build DSL, and then import those from the string that Exec returns. I know that I can write the output to a temporary file and then <Import> it, but doing it in-memory without the need for that would be much more elegant. Thanks in advance! :catlove:
5 Replies
ascpixi
ascpixiOP5mo ago
my use case is for my custom build system to support IDEs that rely on MSBuild (and MSBuild only, like Visual Studio or Rider). i don't wanna delve into too much details, but basically, my script returns something like the following:
<Project>
<!-- This file has been auto-generated. -->
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>
<Project>
<!-- This file has been auto-generated. -->
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>
after an <Exec>, ideally i'd want to just evaluate this in-memory rather than having to write it to a temporary file
reflectronic
reflectronic5mo ago
yeah, you will have to use a temporary file i don't think it will be that inelegant you just need to come up with some file name e.g. DSLGeneratedSomething.g.props, and then you can generate it into $(IntermediateOutputPath) and import it from there that is a pretty standard technique. it is what NuGet does for importing package targets, for example
ascpixi
ascpixiOP5mo ago
ah, alright... is it fine if I immediately delete the file after I import it, or does Import expect the file to exist until the entire build is completed?
reflectronic
reflectronic5mo ago
i don't know, but either way deleting the file is not how this pattern is done you just leave stuff in the obj folder that's how everything else does it
ascpixi
ascpixiOP5mo ago
yeah thats what i've ended up doing, the obj folder was already there so i just left it alone lol although every time that file was modified it triggered a rebuild, so i think it wouldn't work anywho, thanks for your time! :catlove:
Want results from more Discord servers?
Add your server