dotnet / dotnet/msbuild

ImportBefore/After fails on macOS

Open
#11,529 3 comments 2 reactions 0 assignees View on GitHub
OS: macOS Priority:2 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

MSBuild imports all files from ImportBefore and ImportAfter directories without any filters:

https://github.com/dotnet/msbuild/blob/0f466124dc843c0db2c84eedc1b8bebd6f6daff3/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L27

https://github.com/dotnet/msbuild/blob/0f466124dc843c0db2c84eedc1b8bebd6f6daff3/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L391

Therefore, it's impossible to customize local builds on macOS, because Finder creates a .DS_Store file in the directory as it navigates, and MSBuild tries to import it when building a project.

### Steps to Reproduce

1. Create the following directory in Finder: `/Users/USER/Library/ApplicationSupport/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore`
2. Try to build anything with `dotnet build`

### Expected Behavior

Builds succesfully

### Actual Behavior

```
/usr/local/share/dotnet/sdk/9.0.200/Microsoft.Common.CurrentVersion.targets(6998,3): error MSB4024: The imported project file "/Users/USER/Library/Application Support/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore/.DS_Store" could not be loaded. Root element is missing.
```

### Analysis

MSBuild should never try to import from built-in targets without any filters

It's also possible to implement default filters in ``. I think it would be reasonable to ignore hidden files (`File.GetAttributes(path).HasFlag(FileAttributes.Hidden)`)

### Versions & Configurations

`dotnet --version`: 9.0.200
`dotnet msbuild -version`: 17.13.8.7017
macOS: 15.3 (24D60)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.