MSBuild: the task of embedding a file before compilation

I need the following information:

I need to create an MSBuild task that will create an xml file, which then I need to embed as a resource in one of the built projects. How do I change my MSBuild project for this? Is there a built-in task that I can use to embed a file, or do I need to create it? If the latter, any direction in this would be great.

Thanks in advance!

Update. Based on the above suggestions, I added an empty XML file to the project as a resource, creating a simple MSBuild task (http://bartdesmet.net/blogs/bart/archive/2008)./02/15/the-custom-msbuild-task -cookbook.aspx), which writes the contents to this file as needed and runs this task as the "BeforeBuild" target. It works like a charm. Please note that I had to “exclude the file from the source control”, so it will not be checked every time I create a project, and I also added code to the task to make sure the file is not read-only (http: / /www.del337ed.com/blog/index.php/2007/09/05/clearing-the-read-only-flag-on-a-file-in-c/).

+4
source share
2 answers

If you do not need to create the entire Xml file from scratch and you can add the stubb file to your project, you can use the XmlPoke Task to update this file in TargetDefault (see Sergios answer).

0
source

You can use the BeforeBuild file built into the .csproj / .vbproj file (do not forget to uncomment it) and call the required MSBuild task in BeforeTarget. In this project, add this resource as a built-in. All this.

0
source

Source: https://habr.com/ru/post/1337417/


All Articles