How to get extension name (without dot) in MSBuild

I have an ItemGroup and I use its metadata as identifiers in my MSBuild project for batch processing. For example:

<BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)" Message=" - Unit Tests: %(TestSuite.Filename): %(TestSuite.Extension)"> <Output TaskParameter="Id" PropertyName="RunUnitTestsStepId-%(TestSuite.Filename)-%(TestSuite.Extension)" /> </BuildStep> 

However, this will not work, because the extension has a period that is an invalid character for Id (in the BuildStep task). Thus, MSBuild always fails in the BuildStep task.

I am trying to remove a point, but no luck. Maybe there is a way to add some metadata to an existing ItemGroup? Ideally, I would like to have something like% (TestSuite.ExtensionWithoutDot). How can i achieve this?

+2
msbuild metadata
source share
1 answer

I think you are a little confused by what the <Output> element is doing - it will create a property with the name in the PropertyName attribute and set the value of this property as the value of the Id output from the BuildStep task. You do not affect the Id value - you just save it in a property for later reference to set the status of the assembly phase

With that in mind, I don’t understand why you are worried that the created property will have a name that will include the extension concatenation. While the property name is unique, you can refer to it later in the next BuildStep task, and I assume that your testuite file name is enough to indicate uniqueness.

In fact, you could avoid creating unique properties that track each pair of testsuite / buildstep if you made targeted subsidies:

 <Target Name="Build" Inputs="@(TestSuite)" Outputs="%(Identity).Dummy"> <!-- Note that even though it looks like we have the entire TestSuite itemgroup here, We will only have ONE - ie we will execute this target *foreach* item in the group See http://beaucrawford.net/post/MSBuild-Batching.aspx --> <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)" Message=" - Unit Tests: %(TestSuite.Filename): %(TestSuite.Extension)"> <Output TaskParameter="Id" PropertyName="TestStepId" /> </BuildStep> <!-- ..Do some stuff here.. --> <BuildStep Condition=" Evaluate Success Condition Here " TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(TestStepId)" Status="Succeeded" /> <BuildStep Condition=" Evaluate Failed Condition Here " TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(TestStepId)" Status="Failed" /> </Target> 
+3
source share

All Articles