tags:

views:

635

answers:

3

Hi Guys -

I am trying to setup some properties that i use multiple times in my MSBuild script. I have the following property section:

<PropertyGroup>
    <BuildDependsOn>$(BuildDependsOn); MyAfterBuild </BuildDependsOn>
    <SubstitutionsFilePath>$(ProjectDir)app.config.substitutions.xml </SubstitutionsFilePath>
    <AppConfig>$(TargetPath).config</AppConfig>
    <HostConfig>$(TargetDir)$(TargetName).vshost.exe.config</HostConfig>
</PropertyGroup>

When i run this i get the following error:

The expression "@(TargetPath).config" cannot be used in this context. Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists.

I don't understand this error, as the use of the $(BuildDependsOn) and $(ProjectDir) work fine. And i know the $(TargetXXX) values generate properly as when i put them directly into the Tasks section below, they work fine.

Any thoughts?

Regards

Tris

A: 

First try running your build with the /v:diag option, which will output a lot more information and give you a clue as to what part of the build is failing.

A clue might be in the Microsoft.Common.targets file (located in %SystemRoot%\Microsoft.NET\Framework\v2.0.50727) in the PrepareForBuild target:

   <!-- 
    These CreateProperty calls are required because TargetDir and TargetPath are defined 
    to contain an item list. We want that item list to be expanded so that it can be used
    as a regular property value and not as an item-list-with-transform.
    -->
    <CreateProperty Value="$(TargetDir)">
        <Output TaskParameter="Value" PropertyName="TargetDir" />
    </CreateProperty>

    <CreateProperty Value="$(TargetPath)">
        <Output TaskParameter="Value" PropertyName="TargetPath" />
    </CreateProperty>
Todd
+1  A: 

To me this looks like a bug, you can report it at https://connect.microsoft.com/feedback/Search.aspx?SiteID=210.

Sayed Ibrahim Hashimi
+2  A: 

The reason for this problem is that TargetDir is defined as an item list, not a property; presumably to cater to the scenario where your outputs are distributed amongst several output directories?

I came up against this same problem and managed to work around it by using the $(OutDir) property instead of $(TargetDir).

(The OutDir property is defined in Microsoft.Common.Targets (lines 100-102) as a normalised version of the OutputPath defined in your project file.)

Daniel Fortunov