With msbuild how do you specify the optional 'identifier' argument in the Csc Task Resources parameter?

357 views Asked by At

I tried the following msbuild script (with most irrelevant code removed):

<ItemGroup>
    <EmbeddedResource Include="$(ResourceLocation)logom.ico">
        <Id>resources.icon.m</Id>
    </EmbeddedResource>
    <EmbeddedResource Include="$(ResourceLocation)logo.png">
        <Id>resources.image.banner</Id>
    </EmbeddedResource>
</ItemGroup>

<Target Name="build" Inputs="@(Compile)" Outputs="$(OutputPath)$(AssemblyName).exe">
    <ItemGroup>
        <EmbeddedResource>
            <TaggedResource>$([System.String]::Copy('$(ResourceLocation)%(Filename)%(Extension),%(Id)'))</TaggedResource>
        </EmbeddedResource>
    </ItemGroup>

    <Csc
        Sources="@(Compile)"
        Resources="@(EmbeddedResource->'%(TaggedResource)')"
    />
</Target>

which results in output like this (i trimmed some unrelated output):

BuildTools\MSBuild\15.0\Bin\Roslyn\csc.exe /resource:"res\logom.ico,resources.icon.m" /resource:"res\logo.png,resources.image.banner"

I'm trying to take advantage of the optional "identifier" argument for the resource parameter of the Csc task. I think it fails because the output gets quotes around each item, so the Csc task thinks the entire thing is the file name. How can i specify these resource value & argument pairs without the quotes?

This is my first msbuild script, so i could easily be way off target.

1

There are 1 answers

0
marcaroni On

to get the desired result:

<ItemGroup>
    <EmbeddedResource Include="$(ResourceLocation)logom.ico">
        <LogicalName>resources.icon.m</LogicalName>
    </EmbeddedResource>
    <EmbeddedResource Include="$(ResourceLocation)logo.png">
        <LogicalName>resources.image.banner</LogicalName>
    </EmbeddedResource>
</ItemGroup>

<Target Name="build" Inputs="@(Compile)" Outputs="$(OutputPath)$(AssemblyName).exe">
    <Csc
        Sources="@(Compile)"
        Resources="@(EmbeddedResource)"
    />
</Target>

...because "LogicalName" is the metadata entry corresponding to the "identifier" argument.