Standard build variables are not replaced in before/after build scripts.
See original GitHub issueMoving from https://github.com/dotnet/cli/issues/5095 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
- Create a new project (
dotnet new
) - 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>
</PropertyGroup>
- Restore packages. (
dotnet restore
) - 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.
bin\Debug\netcoreapp1.0\
test -> C:\Users\Me\Source\test\bin\Debug\netcoreapp1.0\test.dll
bin\Debug\netcoreapp1.0\
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:
- Created 7 years ago
- Reactions:17
- Comments:23 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You cant just decide to get rid of this. I think thousands of users all over the world use it.
@mgwalm @Ziflin I don’t expect us to make
PreBuildEvent
andPostBuildEvent
get the final values of properties asOutDir
. 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: