I have an MsBuild (csproj) file in which I do some custom conditional items and targets. Everything runs fine for one configuration but I get an error for others that are cloned from the original. The error comes from the fact a custom variable out of a regex does not get set.
Here are the main excerpts from the MsBuild script:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'N1|AnyCPU' ">
<DefineConstants>TRACE;DEBUG;SITE_N1</DefineConstants>
</PropertyGroup>
<PropertyGroup Label="Site Extractor">
<MySite>$([System.Text.RegularExpressions.Regex]::Match($(DefineConstants), '(?<=(?:^|;)SITE_)([^;$]+)(?=;|$)'))</MySite>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'N2|AnyCPU' ">
<DefineConstants>TRACE;DEBUG;SITE_N2</DefineConstants>
</PropertyGroup>
<PropertyGroup Label="N1 Specifics" Condition="$(MySite) == 'N1'">
<SharedResPath>..\..\Resources\N1.1</PathPilotageKX>
</PropertyGroup>
<PropertyGroup Label="N2 Specifics" Condition="$(MySite) == 'N2'">
<SharedResPath>..\..\Resources\N2.0</PathPilotageKX>
</PropertyGroup>
<Target Name="My Validations" BeforeTargets="BeforeBuild">
<Message Text="DefinedConstants: [$(DefineConstants)]" />
<Message Text="Site: [$(MySite)]" />
<Message Text="Shared Res Path: [$(SharedResPath)]" />
<Message Text="Configuration: $(Configuration)" />
<Error Text="Site code (SITE_$(MySite)) is not supported by csproj (MSBuild)." Condition="$(SharedResPath) == ''" />
</Target>
Validation task result is:
My Validations:
DefinedConstants: [TRACE;SITE_N1]
Site: []
Shared Res Path: []
Configuration: N1
##[error]MyProject.csproj(352,5): Error : Site code (SITE_) is not supported by csproj (MSBuild).
Edit 1:
After some more fiddling, it looks like it is not related to Azure DevOps after all since I was able to reproduce the problem on the dev machine; so I removed every mentions of it. Also, it does not seem to neither be related to the value of DefineConstants since copying the value from one that is working to one that is not and vice-versa doesn't change anything.
Edit 2
Since the order of the elements has importance after all, I edited the excerpts to represent what was really in my project. Sorry for misleading, I didn't realize it had importance since my focus was elsewhere.