I need to be able to overrire the name of output assemblies.
There is a file that contains the prefix, appid. I need to read the file to get this prefix and then to use it for assembly name. I.e., assembly name engine.dll and appid contains slot_113. Final output should be engine_slot113.dll.
I'm thinking about to create a separate .targets file, that I'm able to include to any .csproj file that requires that behaviour.
I found a task ReadFileLines to read file contains appid, but I'm not sure how to override output name.
You can easily achieve this by using MSBuild Copy Task.
Let's assume you already extracted suffix in the property $(AssemblyNameSuffix) and specify assembly files item group @(AssemblyDllFiles), so:
RenameDlls.targets file (with content shown below)testfile.txt along with the targets filemsbuild.exe RenameDlls.targetstestfile.txt will be copied as testfile_SUFFIX.txtNote: You can apply this action to multiple files as well
MSBuild targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Default">
<Target Name="Default" DependsOnTargets="CreateItems;CopyItems"/>
<PropertyGroup>
<AssemblyNameSuffix>SUFFIX</AssemblyNameSuffix>
</PropertyGroup>
<Target Name="CreateItems">
<ItemGroup>
<AssemblyDllFiles Include="testfile.txt"/>
</ItemGroup>
</Target>
<Target Name="CopyItems"
Inputs="@(AssemblyDllFiles)"
Outputs="@(AssemblyDllFiles->'.\%(RecursiveDir)%(Filename)_$(AssemblyNameSuffix)%(Extension)')">
<Message Text="@(AssemblyDllFiles->'%(FullPath)', '%0a%0d')"
Importance="low"/>
<Copy SourceFiles="@(AssemblyDllFiles)"
DestinationFiles="@(AssemblyDllFiles->'.\%(RecursiveDir)%(Filename)_$(AssemblyNameSuffix)%(Extension)')"
SkipUnchangedFiles="true"/>
</Target>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With