Stop mutating environment variables during registration
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 64/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- csharp
- Lĩnh vực
- build-system
Hướng nghiên cứu
Bắt đầu với ApplyDotNetSdkEnvironmentVariables và các lệnh gọi của nó từ các đường dẫn đăng ký .NET, sau đó kiểm tra bộ kiểm thử MSBuildLocator hiện có. Thêm độ bao phủ được cô lập theo tiến trình khi thiếu cả ba biến, đăng ký một SDK, đánh giá một dự án kiểu SDK và xác minh các đường dẫn được suy ra. Hoàn thành khi việc đăng ký không còn ghi đè các biến môi trường thuộc quyền quản lý của bên gọi và các kịch bản hồi quy đều vượt qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
On .NET, registration currently calls ApplyDotNetSdkEnvironmentVariables, which sets process-wide environment variables:
MSBUILD_EXE_PATH=<sdk>\MSBuild.dll
MSBuildExtensionsPath=<sdk>
MSBuildSDKsPath=<sdk>\Sdks
This was added to mimic the environment established by dotnet msbuild, but it appears unnecessary. MSBuild can derive its toolset, extensions path, and SDKs path from the loaded MSBuild assemblies.
Proposal: remove ApplyDotNetSdkEnvironmentVariables and stop setting or unsetting these variables during registration. Environment variables supplied by the caller should remain caller-owned.
Copilot analysis of the situation:
Why
MSBuild's
BuildEnvironmentHelperalready has self-location logic:
MSBUILD_EXE_PATHis an explicit override, but when absent MSBuild locates its installation from the loaded assembly and adjacentMSBuild.dll/apphost.MSBuildExtensionsPathdefaults to the detected MSBuild tools directory for a standalone toolset.MSBuildSDKsPathdefaults to<detected MSBuild tools directory>\Sdks.Mutating these variables is process-global and can affect unrelated code and child processes. In particular, a child
dotnetinvocation may select another SDK throughglobal.jsonwhile inheriting paths pinned to the SDK registered in its parent.Experiments
An isolated probe was run in a fresh process for each scenario. It:
- Registered a specific SDK directory before touching any MSBuild API.
- Removed
MSBUILD_EXE_PATH,MSBuildExtensionsPath, andMSBuildSDKsPathbefore MSBuild initialized.- Created and evaluated a minimal SDK-style project.
- Checked the evaluated toolset properties.
- Restored and built the project and verified its output.
- Repeated the build through two parallel out-of-process worker nodes.
Tested SDKs:
SDK MSBuild Project TFM Result 2.1.300 15.7 netcoreapp2.1Passed 8.0.423 17.x net8.0Passed 9.0.316 17.x net9.0Passed 10.0.302 18.x net10.0Passed 10.0.400 preview 18.x net10.0Passed In every case MSBuild derived the selected installation correctly. For SDK 2.1.300, for example:
MSBuildExtensionsPath=<extracted SDK>\sdk\2.1.300 MSBuildSDKsPath=<extracted SDK>\sdk\2.1.300\Sdks MSBuildToolsPath=<extracted SDK>\sdk\2.1.300 MSBuildToolsVersion=15.0Restore, build, output verification, and the parallel-node build all succeeded. The current MSBuildLocator test suite also passed after replacing the environment setup during the experiment.
The SDK 2.1.300 probe used the official Windows x64 archive. The harness itself ran on .NET 8 while loading MSBuild 15.7 from that SDK; it did not cover a .NET Core 2.1-hosted process or Linux.
Compatibility considerations
- Existing ambient values currently get overwritten. With this proposal they would be preserved and would continue to act as explicit MSBuild overrides. That is more conventional, but it is a behavior change for callers with stale or incorrect inherited values.
- Native AOT and unusual bundled hosts can require an explicit toolset path when
Assembly.Locationis unavailable. MSBuildLocator currently relies on runtime assembly loading and does not support the normal Native AOT model, but this should be confirmed before removal.- The oldest supported SDK should also be exercised under its native runtime and on Unix in CI if practical.
Proposed change
- Remove
ApplyDotNetSdkEnvironmentVariablesand its calls from .NET registration paths.- Add process-isolated regression coverage that registers an SDK with all three variables absent, evaluates an SDK-style project, and verifies the derived paths.
- Document that MSBuild-related environment overrides are owned by the host/caller and are not rewritten by MSBuildLocator.
- Ngôn ngữ chính
- C#
- Star
- 262
- Fork
- 91
- Merge trung bình
- 11 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/MSBuildLocator
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
microsoft/MSBuildLocator#390 · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
microsoft/MSBuildLocator#380 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
microsoft/MSBuildLocator#377 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
microsoft/MSBuildLocator#371 · 1 bình luận ·
-
microsoft/MSBuildLocator#368 · 2 bình luận · 4 reaction · 1 người được giao ·
Tất cả issue của microsoft/MSBuildLocator
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/onnxruntime-genai#2633 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
python triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microsoft/semantic-kernel#14491 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area:jobads-cv FE mvp P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
klasolsson81/jobbliggaren#1878 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
pnp/pnpcore#1878 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SubtitleEdit/subtitleedit#15331 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày