问题
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.
回答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.
来源:https://stackoverflow.com/questions/1593902/msbuild-evaluating-reserved-properties-with-readlinesfromfile