@@ -34,23 +34,37 @@ public async Task<SimulationResult> RunAsync(
3434 Log ( $ "STEP 2: Preparing { config . OutputDirectory } ", progress ) ;
3535 Directory . CreateDirectory ( config . OutputDirectory ) ;
3636
37- // 3. Copy test app executables
38- Log ( "STEP 3: Copying test executables " , progress ) ;
37+ // 3. Compile test apps to .exe
38+ Log ( "STEP 3: Compiling test apps " , progress ) ;
3939 var toolsDir = AppDomain . CurrentDomain . BaseDirectory ;
40- var clientSrc = Path . Combine ( toolsDir , "test_app" , "Client.exe " ) ;
41- var upgradeSrc = Path . Combine ( toolsDir , "test_app" , "Upgrade.exe " ) ;
40+ var clientProj = Path . Combine ( toolsDir , ".." , ".." , ".." , ".." , " test_app", "Client" , "ClientSample.csproj ") ;
41+ var upgradeProj = Path . Combine ( toolsDir , ".." , ".." , ".." , ".." , " test_app", "Upgrade" , "UpgradeSample.csproj ") ;
4242
43- if ( ! File . Exists ( clientSrc ) )
44- throw new FileNotFoundException ( $ "Client.exe not found at { clientSrc } . Ensure test_app is deployed.") ;
45- if ( ! File . Exists ( upgradeSrc ) )
46- throw new FileNotFoundException ( $ "Upgrade.exe not found at { upgradeSrc } . Ensure test_app is deployed.") ;
43+ // Normalize paths
44+ clientProj = Path . GetFullPath ( clientProj ) ;
45+ upgradeProj = Path . GetFullPath ( upgradeProj ) ;
4746
47+ if ( ! File . Exists ( clientProj ) )
48+ throw new FileNotFoundException ( $ "Client project not found at { clientProj } ") ;
49+ if ( ! File . Exists ( upgradeProj ) )
50+ throw new FileNotFoundException ( $ "Upgrade project not found at { upgradeProj } ") ;
51+
52+ var exeDir = Path . Combine ( toolsDir , "test_app" ) ;
53+ Directory . CreateDirectory ( exeDir ) ;
54+
55+ Log ( " Compiling Client.exe..." , progress ) ;
56+ await DotNetPublishAsync ( clientProj , exeDir ) ;
57+ Log ( $ " Client.exe → { exeDir } ", progress ) ;
58+
59+ Log ( " Compiling Upgrade.exe..." , progress ) ;
60+ await DotNetPublishAsync ( upgradeProj , exeDir ) ;
61+ Log ( $ " Upgrade.exe → { exeDir } ", progress ) ;
62+
63+ // Copy to simulation output
4864 var clientDest = Path . Combine ( config . OutputDirectory , "Client.exe" ) ;
4965 var upgradeDest = Path . Combine ( config . OutputDirectory , "Upgrade.exe" ) ;
50- File . Copy ( clientSrc , clientDest , true ) ;
51- File . Copy ( upgradeSrc , upgradeDest , true ) ;
52- Log ( $ " Client.exe → { config . OutputDirectory } ", progress ) ;
53- Log ( $ " Upgrade.exe → { config . OutputDirectory } ", progress ) ;
66+ File . Copy ( Path . Combine ( exeDir , "ClientSample.exe" ) , clientDest , true ) ;
67+ File . Copy ( Path . Combine ( exeDir , "UpgradeSample.exe" ) , upgradeDest , true ) ;
5468
5569 // 4. Start server
5670 Log ( "STEP 4: Starting local server" , progress ) ;
@@ -109,6 +123,26 @@ public async Task<SimulationResult> RunAsync(
109123 return result ;
110124 }
111125
126+ private static async Task DotNetPublishAsync ( string projectPath , string outputDir )
127+ {
128+ var psi = new ProcessStartInfo ( "dotnet" , $ "publish \" { projectPath } \" -c Release -r win-x64 -p:PublishSingleFile=true --self-contained -p:PublishTrimmed=true -o \" { outputDir } \" ")
129+ {
130+ RedirectStandardOutput = true ,
131+ RedirectStandardError = true ,
132+ UseShellExecute = false ,
133+ CreateNoWindow = true
134+ } ;
135+ using var p = Process . Start ( psi ) ! ;
136+ var outTask = p . StandardOutput . ReadToEndAsync ( ) ;
137+ var errTask = p . StandardError . ReadToEndAsync ( ) ;
138+ await p . WaitForExitAsync ( ) ;
139+ if ( p . ExitCode != 0 )
140+ {
141+ var err = await errTask ;
142+ throw new InvalidOperationException ( $ "dotnet publish failed (exit { p . ExitCode } ):\n { err } ") ;
143+ }
144+ }
145+
112146 private void Validate ( SimulateConfigModel config )
113147 {
114148 if ( ! Directory . Exists ( config . AppDirectory ) )
0 commit comments