Skip to content

Instantly share code, notes, and snippets.

@ricaun
Forked from esfand/PrintValues
Created July 11, 2022 22:14
Show Gist options
  • Save ricaun/affc3f1a9e334177d33eb929acb9d46c to your computer and use it in GitHub Desktop.
Save ricaun/affc3f1a9e334177d33eb929acb9d46c to your computer and use it in GitHub Desktop.
MSBuild Property Demo
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="PrintValues"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Add>$([MSBuild]::Add(5,9))</Add>
<Subtract01>$([MSBuild]::Subtract(90,768))</Subtract01>
<Mult01>$([MSBuild]::Multiply(4,9))</Mult01>
<Div01>$([MSBuild]::Divide(100,5.2))</Div01>
</PropertyGroup>
<PropertyGroup>
<SampleString>This is a sample string</SampleString>
<SampleString2> This is a sample string </SampleString2>
<!-- Here we now can call instance methods on the String class -->
<Sub04>$(SampleString.Substring(0,4))</Sub04>
<Contains01>$(SampleString.Contains("This"))</Contains01>
<Contains02>$(SampleString.Contains("this"))</Contains02>
<CompareTo01>$(SampleString.CompareTo($(SampleString)))</CompareTo01>
<EndsWith01>$(SampleString.CompareTo("string"))</EndsWith01>
<Insert01>$(SampleString.Insert(2,"INSERTED"))</Insert01>
<Trim01>$(SampleString2.Trim())</Trim01>
</PropertyGroup>
<PropertyGroup>
<!--
Here we Now01 can call static methods/properties on many types
See http://msdn.microsoft.com/en-us/library/dd633440%28VS.100%29.aspx
for the list of classes that we can call static methods/properties on.
-->
<Now01>$([System.DateTime]::Now)</Now01>
<Pow01>$([System.Math]::Pow(2,3))</Pow01>
<TempFile01>$([System.IO.Path]::GetTempFileName())</TempFile01>
</PropertyGroup>
<Target Name="PrintValues">
<Message Text="Add: $(Add)" Importance="high"/>
<Message Text="Subtract01: $(Subtract01)" Importance="high"/>
<Message Text="Mult01: $(Mult01)" Importance="high"/>
<Message Text="Div01: $(Div01)" Importance="high"/>
<Message Text="-----------------------"/>
<Message Text="Now01: $(Now01)" Importance="high"/>
<Message Text="Pow01: $(Pow01)" Importance="high"/>
<Message Text="TempFile01: $(TempFile01)" Importance="high"/>
<Message Text="-----------------------"/>
<Message Text="SampleString: $(SampleString)" Importance="high"/>
<Message Text="Sub04: $(Sub04)" Importance="high"/>
<Message Text="Contains01: $(Contains01)" Importance="high"/>
<Message Text="Contains02: $(Contains02)" Importance="high"/>
<Message Text="CompareTo01: $(CompareTo01)" Importance="high"/>
<Message Text="EndsWith01: $(EndsWith01)" Importance="high"/>
<Message Text="Insert01: $(Insert01)" Importance="high"/>
<Message Text="Trim01: $(Trim01)" Importance="high"/>
<Message Text="-----------------------"/>
<Message Text="MSBuild: $(MSBuild)"/>
<Message Text="MSBuildBinPath: $(MSBuildBinPath)"/>
<Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)"/>
<Message Text="MSBuildExtensionsPath32: $(MSBuildExtensionsPath32)"/>
<Message Text="MSBuildExtensionsPath64: $(MSBuildExtensionsPath64)"/>
<Message Text="MSBuildLastTaskResult: $(MSBuildLastTaskResult)"/>
<Message Text="MSBuildNodeCount: $(MSBuildNodeCount)"/>
<Message Text="MSBuildOverrideTasksPath: $(MSBuildOverrideTasksPath)"/>
<Message Text="MSBuildProgramFiles32: $(MSBuildProgramFiles32)"/>
<Message Text="MSBuildProjectDefaultTargets: $(MSBuildProjectDefaultTargets)"/>
<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/>
<Message Text="MSBuildProjectDirectoryNoRoot: $(MSBuildProjectDirectoryNoRoot)"/>
<Message Text="MSBuildProjectExtension: $(MSBuildProjectExtension)"/>
<Message Text="MSBuildProjectFile: $(MSBuildProjectFile)"/>
<Message Text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)"/>
<Message Text="MSBuildProjectName: $(MSBuildProjectName)"/>
<Message Text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)"/>
<Message Text="MSBuildThisFile: $(MSBuildThisFile)"/>
<Message Text="MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)"/>
<Message Text="MSBuildThisFileDirectoryNoRoot: $(MSBuildThisFileDirectoryNoRoot)"/>
<Message Text="MSBuildThisFileExtension: $(MSBuildThisFileExtension)"/>
<Message Text="MSBuildThisFileFullPath: $(MSBuildThisFileFullPath)"/>
<Message Text="MSBuildThisFileName: $(MSBuildThisFileName)"/>
<Message Text="MSBuildToolsPath: $(MSBuildToolsPath)"/>
<Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)"/>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment