@@ -74,42 +74,70 @@ public void MigrationChecksTargets_ShouldNotUseReadAllLines()
7474 // -----------------------------------------------------------------------
7575
7676 [ Fact ]
77- public async Task MigrationChecksTargets_BuildWithPackageJsonContainingElectron_ShouldSucceedWithoutMSB4185 ( )
77+ public async Task MigrationChecksTargets_BuildWithCleanPackageJson_ShouldSucceedWithoutMSB4185 ( )
7878 {
79- var tempDir = Path . Combine ( Path . GetTempPath ( ) , $ "electron-net-test-{ Guid . NewGuid ( ) : N} ") ;
80- Directory . CreateDirectory ( tempDir ) ;
79+ // Positive case: a package.json that does NOT mention electron.
80+ // The migration check must successfully read the file via ReadAllText
81+ // (the code path fixed by issue #1035) without producing MSB4185.
82+
83+ var tempDir = CreateTempProjectDirectory ( ) ;
8184 try
8285 {
83- // Create a minimal package.json that contains "electron" so ELECTRON008 fires.
8486 await File . WriteAllTextAsync (
8587 Path . Combine ( tempDir , "package.json" ) ,
86- """{ "devDependencies": { "electron": "^30.0.0" } }""" ) ;
88+ """{ "devDependencies": { "vite": "^5.0.0" } }""" ) ;
89+
90+ await WriteMinimalCsprojAsync ( tempDir ) ;
91+
92+ var ( exitCode , output ) = await RunDotnetBuildAsync ( tempDir ) ;
93+
94+ exitCode . Should ( ) . Be ( 0 ,
95+ $ "the build must succeed when the package.json contains no electron references. " +
96+ $ "Full build output:\n { output } ") ;
8797
88- // Create a minimal csproj that only imports the migration checks targets.
89- // We deliberately import just that one targets file to keep the build fast.
90- // Note: MSBuildProjectDirectory is a reserved MSBuild property - it must not be
91- // redefined manually. MSBuild sets it automatically to the csproj's folder (tempDir).
92- var targetsPathEscaped = TargetsFilePath . Replace ( "'" , "'" ) ;
98+ output . Should ( ) . NotContain (
99+ "MSB4185" ,
100+ $ "ReadAllLines must not be used as an MSBuild property function. " +
101+ $ "Full build output:\n { output } ") ;
102+ }
103+ finally
104+ {
105+ Directory . Delete ( tempDir , recursive : true ) ;
106+ }
107+ }
108+
109+ [ Fact ]
110+ public async Task MigrationChecksTargets_BuildWithPackageJsonContainingElectron_ShouldEmitELECTRON008WarningWithoutMSB4185 ( )
111+ {
112+ // Negative case: a package.json that DOES contain "electron".
113+ // The migration check must still read the file successfully (no MSB4185)
114+ // and must emit the expected ELECTRON008 warning. ELECTRON008 is a
115+ // <Warning>, not an <Error>, so the build itself still succeeds.
116+
117+ var tempDir = CreateTempProjectDirectory ( ) ;
118+ try
119+ {
93120 await File . WriteAllTextAsync (
94- Path . Combine ( tempDir , "TestApp.csproj" ) ,
95- $ """
96- <Project>
97- <Import Project="{ targetsPathEscaped } " />
98- <Target Name="Build" DependsOnTargets="ElectronMigrationChecks" />
99- </Project>
100- """ ) ;
101-
102- // ACT - run the Build target
121+ Path . Combine ( tempDir , "package.json" ) ,
122+ """{ "devDependencies": { "electron": "^30.0.0" } }""" ) ;
123+
124+ await WriteMinimalCsprojAsync ( tempDir ) ;
125+
103126 var ( exitCode , output ) = await RunDotnetBuildAsync ( tempDir ) ;
104127
105- // ASSERT - the build must succeed and must not produce MSB4185
106128 exitCode . Should ( ) . Be ( 0 ,
107- $ "the temporary MSBuild project should build successfully. Full build output:\n { output } ") ;
129+ $ "ELECTRON008 is a Warning (not an Error) so the build itself must still " +
130+ $ "succeed. Full build output:\n { output } ") ;
108131
109132 output . Should ( ) . NotContain (
110133 "MSB4185" ,
111134 $ "ReadAllLines must not be used as an MSBuild property function. " +
112135 $ "Full build output:\n { output } ") ;
136+
137+ output . Should ( ) . Contain (
138+ "ELECTRON008" ,
139+ $ "the migration check must still detect electron references in package.json " +
140+ $ "after the ReadAllText migration. Full build output:\n { output } ") ;
113141 }
114142 finally
115143 {
@@ -118,9 +146,33 @@ await File.WriteAllTextAsync(
118146 }
119147
120148 // -----------------------------------------------------------------------
121- // Helper
149+ // Helpers
122150 // -----------------------------------------------------------------------
123151
152+ private static string CreateTempProjectDirectory ( )
153+ {
154+ var tempDir = Path . Combine ( Path . GetTempPath ( ) , $ "electron-net-test-{ Guid . NewGuid ( ) : N} ") ;
155+ Directory . CreateDirectory ( tempDir ) ;
156+ return tempDir ;
157+ }
158+
159+ private static Task WriteMinimalCsprojAsync ( string tempDir )
160+ {
161+ // A minimal csproj that only imports the migration checks targets to keep the
162+ // build fast. Note: MSBuildProjectDirectory is a reserved MSBuild property and
163+ // must not be redefined manually; MSBuild sets it automatically to the folder
164+ // of the csproj (which is tempDir here).
165+ var targetsPathEscaped = TargetsFilePath . Replace ( "'" , "'" ) ;
166+ return File . WriteAllTextAsync (
167+ Path . Combine ( tempDir , "TestApp.csproj" ) ,
168+ $ """
169+ <Project>
170+ <Import Project="{ targetsPathEscaped } " />
171+ <Target Name="Build" DependsOnTargets="ElectronMigrationChecks" />
172+ </Project>
173+ """ ) ;
174+ }
175+
124176 private static async Task < ( int ExitCode , string Output ) > RunDotnetBuildAsync ( string workingDirectory )
125177 {
126178 var psi = new ProcessStartInfo ( "dotnet" , "build --nologo -v:minimal" )
0 commit comments