Justin Olbrantz
Justin Olbrantz

Reputation: 649

VS custom build step + embedded resource =?

In Visual Studio 2022 with C#/.NET, how can I have some files that are compiled by a custom build tool then have the output of that tool be included as embedded resources (e.g. Build Action: Embedded Resource) in the resulting assembly?

EDIT: I just ran across a way to do this (though it would be nice if there were a better way). It's possible to edit Visual Studio project files to refer to files that don't actually exist on disk (or not yet), and you can even set them to embedded resources. One way to do this would then be to create pre-build steps to invoke the compiler for each file, then use the project editing trick to include the output files as embedded resources. It works, though having to do two completely different things in completely different places for each file is not ideal; it would be really nice if there were a way to instead of specifying "embedded resource" you could specify "build with x then include as embedded resource".

Also, there is an issue with this approach, at least if your custom compiler is itself a project built in the solution. I'm not yet sure if it's inherent to MSBuild or if it only occurs with GitHub actions, but when you do this, pre-build steps of let's call it Project A can occur BEFORE Project B builds, even when Project B is set as a dependency of Project A. Obviously this causes the pre-build steps to fail because the compiler doesn't exist yet...

Upvotes: 0

Views: 80

Answers (0)

Related Questions