MSBuild: Evaluating reserved properties with ReadLinesFromFile
Asked Answered
I

1

0

I'm using MSBuild to customize the build process of Visual Studio, WiX, SandCastle, ... projects. To keep it as generic as possible I'd like to use text files defining some 'project specific' settings, like where the files should be loaded from, which custom executables to run and so on.

A text file could look like this: $(MSBuildProjectDirectory)....\Projects\Project1\bin\Release obj\$(Configuration)\Project1.Files.wxi -in *.dll -id TEST

Each line represents one command or file.

Inside my targets I'm using ReadLinesFromFile to get the contents of these files. So far so good!

The problem is that the reserved properties like '$(Configuration), $(MSBuildProjectDirectory)' are not evaluated when doing so, they are just processed as regular text.

Any ideas on how I could evaluate these $-placeholders without creating a custom task?

Thanks in advance!

Regards, robert.oh.

Instruct answered 20/10, 2009 at 11:18 Comment(0)
B
1

Rather than reading the lines and parsing everything yourself, why not create a separate file (named, for example, "local.build.config") that has the

<PropertyGroup>
    <someproperty>$(MSBuildProjectDirectory)..\Projects\Project1\bin\Release</someproperty>
</PropertyGroup>

information in the file, and then in your actual project do an import of the file with a line such as this at the top of your build:

<Import Project="local.build.config" Condition="Exists('local.build.config')"/>

Prevents reinventing the wheel by letting the MSBuild engine do what it does best.

Bankruptcy answered 20/10, 2009 at 14:11 Comment(2)
Thanks for advice!<br/>I'm using ItemGroups for my list of commands (one Item per command) and everything works fine now.Instruct
+1 This is a good idea, but to get the example to work for me, I had to add <Project xmlns="schemas.microsoft.com/developer/msbuild/2003"> </Project> around the PropertyGroup.Ezana

© 2022 - 2024 — McMap. All rights reserved.