Skip to content

fix: replace ReadAllLines with ReadAllText in MigrationChecks.targets…#1062

Merged
GregorBiswanger merged 5 commits intodevelopfrom
feature/fix-1035-migration-check-readalllines
May 9, 2026
Merged

fix: replace ReadAllLines with ReadAllText in MigrationChecks.targets…#1062
GregorBiswanger merged 5 commits intodevelopfrom
feature/fix-1035-migration-check-readalllines

Conversation

@GregorBiswanger
Copy link
Copy Markdown
Member

… (fixes #1035)

System.IO.File::ReadAllLines is not available as an MSBuild property function on all platforms (e.g. macOS GitHub Actions), causing MSB4185.

ReadAllText is universally supported by MSBuild and sufficient for the regex check that detects 'electron' references in a root package.json (ELECTRON008). The intermediate ItemGroup for line accumulation is no longer needed.

…fixes #1035)

System.IO.File::ReadAllLines is not available as an MSBuild property function on
all platforms (e.g. macOS GitHub Actions), causing MSB4185.

ReadAllText is universally supported by MSBuild and sufficient for the regex check
that detects 'electron' references in a root package.json (ELECTRON008).
The intermediate ItemGroup for line accumulation is no longer needed.
Copilot AI review requested due to automatic review settings May 9, 2026 19:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes cross-platform MSBuild failure (MSB4185) by switching the migration check to use a universally supported MSBuild property function, and adds regression tests for issue #1035.

Changes:

  • Replace System.IO.File::ReadAllLines usage with System.IO.File::ReadAllText in ElectronNET.MigrationChecks.targets.
  • Remove the intermediate ItemGroup used to accumulate file lines.
  • Add integration tests to prevent regressions and validate no MSB4185 during a real dotnet build.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/ElectronNET/build/ElectronNET.MigrationChecks.targets Switches package.json reading to ReadAllText and simplifies the target.
src/ElectronNET.IntegrationTests/Tests/MigrationChecksTargetsTests.cs Adds coverage to detect ReadAllLines usage and to ensure builds don’t emit MSB4185.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +76 to +82
var (exitCode, output) = await RunDotnetBuildAsync(tempDir);

// ASSERT — the build must not produce the MSB4185 "unavailable function" error
output.Should().NotContain(
"MSB4185",
$"ReadAllLines must not be used as an MSBuild property function. " +
$"Full build output:\n{output}");
Comment on lines +62 to +73
var targetsPathEscaped = TargetsFilePath.Replace("'", "'");
await File.WriteAllTextAsync(
Path.Combine(tempDir, "TestApp.csproj"),
$"""
<Project>
<PropertyGroup>
<MSBuildProjectDirectory>{tempDir}</MSBuildProjectDirectory>
</PropertyGroup>
<Import Project="{targetsPathEscaped}" />
<Target Name="Build" DependsOnTargets="ElectronMigrationChecks" />
</Project>
""");
Comment on lines +67 to +69
<PropertyGroup>
<MSBuildProjectDirectory>{tempDir}</MSBuildProjectDirectory>
</PropertyGroup>
Comment on lines +15 to +19
private static readonly string TargetsFilePath = Path.GetFullPath(
Path.Combine(
AppContext.BaseDirectory,
"..", "..", "..", "..", "..",
"ElectronNET", "build", "ElectronNET.MigrationChecks.targets"));
@GregorBiswanger GregorBiswanger merged commit 50c9076 into develop May 9, 2026
1 of 3 checks passed
@GregorBiswanger GregorBiswanger deleted the feature/fix-1035-migration-check-readalllines branch May 9, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants