I have a bunch of C++ projects (.vcxproj) for VS2017, which produce dynamic libraries (DLL), which are handled like "plugins" (i.e. they are loaded dynamically by the application).
Occasionally I want to change the produced DLLs names based on some list in text file (the format may be changed):
ProjName1;DLL1
ProjName2;DLL2
...
The first column specifies the project name ($(ProjectName)
) and the second is for desired DLL name ($(TargetName)
).
I want this file to be parsed at build-time, so each read DLL name goes into $(OutputFile)
of the appropriate project.
For instance, ProjName1.vcxproj
will have following fragment (at build time):
<Link>
<OutputFile>$(OutDir)DLL1$(TargetExt)</OutputFile>
</Link>
I guess, certain capabilities of msbuild
can be utilized for this (e.g., ReadLinesFromFile task and FindInList task), but I'm not sure how to put these pieces together).
There are some examples of such automation to consider, though I doubt they are relevant to .vcxproj format:
- MSBuild ReadLinesFromFile all text on one line
- Read text file and split every line in MSBuild
- Used ReadLinesFromFile to make version in separate file
The straightforward approach is to modify content of each .vcxproj-file to match the list (either manually, or with some script).
Are there any other options?
Update 1: I've managed to implement a partial solution, which is based on a separate file with DLL name (module name) for each project (refer to Property Functions for more hints).
With property sheets it was easy in my case to 'inject' the fix into all projects:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<PropertyGroup Condition="exists('$(MSBuildProjectDirectory)\_MODULE.name')">
<ModuleName>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\_MODULE.name'))</ModuleName>
<TargetName>$(ModuleName)</TargetName>
</PropertyGroup>
...
</Project>
Though it works quite good, the approach doesn't meet my needs perfectly - I'd like to have all module names in one file.