title: Azure DevOps - Set a Build variable using another variable (nested/composed variables)
body: <p>In Azure DevOps I have a Pipeline variable "package version" and I set it using <code>0.1.3$(Rev:.r)-alpha</code> .</p>
  
  <p><a href="https://i.stack.imgur.com/OS94q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OS94q.png" alt="enter image description here"></a></p>
  
  <p>I use that variable to replace the "Version" in the .net core project file.</p>
  
  <p>In the Build tasks the <em>dotnet build</em> give me this error:</p>
  
  <p><a href="https://i.stack.imgur.com/uO842.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uO842.png" alt="enter image description here"></a></p>
  
  <p>so I assume the Pipeline variable cannot use a nested variable.</p>
  
  <p>There is a nother way or a different syntax to do it?</p>
  
  <p><strong>[Edit]</strong><br>
  The nested variables should work.
  I think the error was the dotnet pack using Automatic package versioning set to "Use the build number" that contain the wrong <code>$(rev:.r)</code> (lowercase!).</p>
  
  <p>Using a custom string for Version in the VS project file gives noise on VS (error if the file is open, warning otherwise) and now the Pipeline Build give me an error on dotnet nuget restore because of the invalid Version.</p>
  
  <p>I decided to use a simple clean version, <code>&lt;Version&gt;0.1.2&lt;/Version&gt;</code>, that I can choose and document.
  Then I want to find a way to read it in the build pipeline and create a custom variable attaching the Build Revision:<br>
  <strong>0.1.2$(Rev:.r)</strong>  =>  0.1.2.123  </p>
  
  <p><strong>That is the result I want.</strong></p>
  
  <p>I found this:  <a href="https://marketplace.visualstudio.com/items?itemName=tmarkovski.projectversionasvariable" rel="nofollow noreferrer">https://marketplace.visualstudio.com/items?itemName=tmarkovski.projectversionasvariable</a></p>
  
  <p>I'm using it with the default settings.
  <a href="https://i.stack.imgur.com/xAosL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xAosL.png" alt="enter image description here"></a></p>
  
  <p>I'm using the variables it creates to compose a new variable, "package version":  </p>
  
  <p><a href="https://i.stack.imgur.com/fIPDL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fIPDL.png" alt="enter image description here"></a></p>
  
  <p>and I use that in the <em>nuget pack</em> task:  </p>
  
  <p><a href="https://i.stack.imgur.com/r9npr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r9npr.png" alt="enter image description here"></a></p>
  
  <p>but it does not work.<br>
  The resulting variable still contain "$(Rev:.r)" not parsed.</p>
  
  <p>I'll try to use again the "Automatic package versioning" and create the build number in the Options...</p>
  
  <p><strong>[Edit 2]</strong><br>
  Set the build version number in the Pipeline Build Options worked.<br>
  It's not the optimal solution because the Build Number is not parsed and looks awful.  </p>
  
  <p><a href="https://i.stack.imgur.com/aaYvw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aaYvw.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/5788e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5788e.png" alt="enter image description here"></a></p>
  
  <p><strong>[Solution]</strong>  </p>
  
  <p><code>$(Rev:.r)</code> is not available outside Build / Options.<br>
  I used <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=vsts" rel="nofollow noreferrer">$(Build.BuildNumber)</a> and I'm able to create a composed variable: 
  <code>$(Version.MajorMinor).$(Build.BuildNumber)-alpha</code></p>
  
  <p><em>Build.BuildNumber</em> is valorized in Build/Options: <code>$(Build.DefinitionVersion)$(Rev:.r)</code></p>
  
  <p><em>Version.MajorMinor</em> is created by the <a href="https://marketplace.visualstudio.com/items?itemName=tmarkovski.projectversionasvariable" rel="nofollow noreferrer">Project Version As Build Variable</a> add-on.<br>
  I don't know how to obtain the same result without using a third party component.</p>