Thomas
Thomas

Reputation: 1160

let msbuild generate target file names from source file names

I'm trying to figure out how to use MSBuild to create a set of dlls from a set of config files. That is, I have some config files

Policy.1.1.mylib.config
Policy.1.2.mylib.config
...
Policy.1.x.mylib.config

and in an msbuild target I'd like to call the AL (assembly linker) task with the list of these files, with the Outputfile parameter value (Policy.1.i.mylib.dll for each i = 1, ..., x) generated dynamically from the correesponding config file parameter. (All other parameters are explicitly known to me, so I can enter them directly).

I don't have much experience with MSBuild. I figured out how to run the AL task in a post build target for one file, and how to get the list of config file names into a list and do think I'd be able to loop over that list using batching, but I'm stuck when it comes to generate the target file name from the source file name.

(Note: This is msbuild 3.5, so seemingly there is no string manipulation as it seems to be in 4.0. Also installing additional libs from the net is not an option for me.)

Any suggestions? Maybe the approach as such is not well suited for MSBuild and I just don't see the proper way of doing this. The config files are generated programatically, maybe I should just in addition to these create a set of files to process, each containing the input and output names for al and have these read by MSBuild?

Upvotes: 1

Views: 1113

Answers (2)

Aaron Jensen
Aaron Jensen

Reputation: 26749

If you just want to create a list of assembly file names, create them in an item group by batching over the config file names:

<ItemGroup>
    <ConfigFiles Include="Path\to\Policy.*.config" />
    <Assemblies Include="%(ConfigFiles.Filename).dll" />
</ItemGroup>

The Assemblies item group will contain

Policy.1.1.mylib.dll
Policy.1.2.mylib.dll
...
Policy.1.x.mylib.dll

Upvotes: 2

Ilya Kozhevnikov
Ilya Kozhevnikov

Reputation: 10432

You'd group the configs with an ItemGroup and that would give you access to metadata for foreach-like looping and recreating a dll name, e.g. <Task Input="%(Configs.FullName)" Output="%(Configs.RelativeDir)\%(Configs.Filename).dll" />

Upvotes: 1

Related Questions