Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standard build variables are not replaced in before/after build scripts.

See original GitHub issue

Moving from on behalf of @mdekrey

Sorry if this isn’t the right spot; I wasn’t sure if the MSBuild repo was a better location for this report or not. Simplest steps are below, but I originally accessed this via Visual Studio, which gave menus for the “macro” variables that did not get replaced. Note that this occurs for both project variables, not just solution variables, as the example uses the dotnet cli.

Steps to reproduce

  1. Create a new project (dotnet new)
  2. Modify your .csproj to have PreBuildEvent or PostBuildEvent that uses build variables as documented in previous C# projects. For example:
    <PropertyGroup Label="Configuration">
      <PreBuildEvent>echo $(OutDir)</PreBuildEvent>
      <PostBuildEvent>echo $(OutDir)</PostBuildEvent>
  1. Restore packages. (dotnet restore)
  2. Build the project. (dotnet build)

Expected behavior

Standard build variables should be replaced in before/after build scripts.

Microsoft (R) Build Engine version 15.1.458.808
Copyright (C) Microsoft Corporation. All rights reserved.

  test -> C:\Users\Me\Source\test\bin\Debug\netcoreapp1.0\test.dll

Actual behavior

Standard build variables are not replaced in before/after build scripts.

Microsoft (R) Build Engine version 15.1.458.808
Copyright (C) Microsoft Corporation. All rights reserved.

  ECHO is on.
  test -> C:\Users\Me\Source\test\bin\Debug\netcoreapp1.0\test.dll
  ECHO is on.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview4-004233)

Product Information:
 Version:            1.0.0-preview4-004233
 Commit SHA-1 hash:  8cec61c6f7

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0-preview4-004233

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:17
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

mgwalmcommented, Feb 15, 2017

You cant just decide to get rid of this. I think thousands of users all over the world use it.

dsplaistedcommented, Feb 15, 2017

@mgwalm @Ziflin I don’t expect us to make PreBuildEvent and PostBuildEvent get the final values of properties as OutDir. If anything we would disable them entirely in .NET SDK projects to avoid people hitting this issue.

Instead, what you can do is use targets to do this. Here’s an example:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo Before Build: $(OutDir)" />

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="echo After Build: $(OutDir)" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Make environment variables set in before_script available ...
The script would echo the value of whoami because it's running on the runner, but the environment name and URL cannot see the...
Read more >
Define variables - Azure Pipelines
Variables are name-value pairs defined by you for use in a pipeline. You can use variables as inputs to tasks and in your...
Read more >
Use predefined variables - Azure Pipelines
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to...
Read more >
Setting environment variables in pre-build event and using ...
Upgrading to version 1.0.1 of my_lib is then simply a matter of editing the svn:externals property -- the code and project settings did...
Read more >
Understanding Azure DevOps Variables [Complete Guide]
Learn just about every concept variables in this article and apply this knowledge to your Azure DevOps Pipelines to automate all the things....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found