Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [BuildCheck]: BC0103 used environment variable does not trigger when property is defined in target #10431

Closed
Tracked by #10316
AR-May opened this issue Jul 23, 2024 · 0 comments · Fixed by #10502
Assignees
Labels
Area: BuildCheck bug Priority:2 Work that is important, but not critical for the release triaged

Comments

@AR-May
Copy link
Member

AR-May commented Jul 23, 2024

Issue Description

Used environment variable analyzer behavior differs: If assignment happened outside the target the message appears and when in the target it does not. From the BC0103 rule documentation I am unable to figure out whether this is expected behavior or a bug.

Steps to Reproduce

  1. Create a project env_var.proj with following content:
<Project>
  <Target Name="Hello">
    <PropertyGroup>
      <ReadFromEnvVariable>$(TEST)</ReadFromEnvVariable>
    </PropertyGroup>
    <Message Importance="High" Text="$(ReadFromEnvVariable)" />
  </Target>
</Project>
  1. Define the env variable: $env:TEST="test"
  2. Build with analyzers: MSBuild.exe .\env_var.proj /m:1 /analyze /t:Hello

Expected Behavior

Build outputs

MSBuild.exe .\env_var.proj /m:1 /analyze /t:Hello
MSBuild version 17.12.0-dev-24373-01+8b03742aa for .NET Framework
Build started 7/23/2024 4:43:07 PM.
The BuildCheck is enabled for this build.
C:\Users\alinama\work\shared-ouput\env-var\env_var.proj (3,5): https://aka.ms/buil
dcheck/codes#BC0103 - Property is derived from environment variable: 'TEST' with v
alue: 'test'. Properties should be passed explicitly using the /p option.
Project "C:\Users\alinama\work\shared-ouput\env-var\env_var.proj" on node 1 (Hello
 target(s)).
Hello:
  test
Done Building Project "C:\Users\alinama\work\shared-ouput\env-var\env_var.proj" (H
ello target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Actual Behavior

Build outputs

Build started 7/23/2024 4:43:26 PM.
The BuildCheck is enabled for this build.
Project "C:\Users\alinama\work\shared-ouput\env-var\env_var.proj" on node 1 (Hello
 target(s)).
Hello:
  test
Done Building Project "C:\Users\alinama\work\shared-ouput\env-var\env_var.proj" (H
ello target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.60

Analysis

If assignment happened outside the target, the output consists of the BC0103 message:

<Project>
  <PropertyGroup>
    <ReadFromEnvVariable>$(TEST)</ReadFromEnvVariable>
  </PropertyGroup>
  <Target Name="Hello">
    <Message Importance="High" Text="$(ReadFromEnvVariable)" />
  </Target>
</Project>

What is interesting is that we have BC0103 test that checks the assignment in the target, and it throws the message BC0103. I am yet unsure what is exactly different in these two cases and brings such difference.

Versions & Configurations

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BuildCheck bug Priority:2 Work that is important, but not critical for the release triaged
Projects
None yet
3 participants