Skip to content

Commit 8bd58a4

Browse files
committed
Show user winget command line
1 parent 410f31d commit 8bd58a4

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/winapp-npm/cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
const { generateAddonFiles } = require('./addon-utils');
4-
const { generateCsAddonFiles, checkAndInstallDotnet10Sdk } = require('./cs-addon-utils');
4+
const { generateCsAddonFiles, checkAndInstallDotnet10Sdk, checkAndInstallVisualStudioBuildTools } = require('./cs-addon-utils');
55
const { addElectronDebugIdentity } = require('./msix-utils');
66
const { getWinappCliPath, callWinappCli, WINAPP_CLI_CALLER_VALUE } = require('./winapp-cli-utils');
77
const { spawn, exec } = require('child_process');
@@ -288,9 +288,13 @@ async function handleCreateAddon(args) {
288288
verbose: options.verbose
289289
});
290290

291+
// Check for Visual Studio Build Tools and offer to install if missing
292+
await checkAndInstallVisualStudioBuildTools(options.verbose);
293+
291294
console.log(`✅ Addon files generated successfully!`);
292295
console.log(`📦 Addon name: ${result.addonName}`);
293296
console.log(`📁 Addon path: ${result.addonPath}`);
297+
294298
console.log(`🔨 Build with: npm run build-${result.addonName}`);
295299
console.log(`🔨 In your source, import the addon with:`);
296300
console.log(` "const ${result.addonName} = require('./${result.addonName}/build/Release/${result.addonName}.node')";`);

src/winapp-npm/cs-addon-utils.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ async function generateCsAddonFiles(options = {}) {
2121
// Validate addon name (should be a valid C# namespace/class name)
2222
validateAddonName(name);
2323

24-
2524
await checkAndInstallVisualStudioBuildTools(false); // Don't show verbose build tools info
2625

2726
// Check if dotnet SDK is available and offer to install if missing
@@ -361,6 +360,14 @@ async function updateGitignore(projectRoot, verbose) {
361360
}
362361
}
363362

363+
/**
364+
* Get the winget command line for installing .NET 10 SDK
365+
* @returns {string} The winget command line
366+
*/
367+
function getDotnet10SdkWingetCommand() {
368+
return 'winget install --id Microsoft.DotNet.SDK.10 --source winget';
369+
}
370+
364371
/**
365372
* Check for .NET 10 SDK and offer to install if missing
366373
* @param {boolean} verbose - Enable verbose logging
@@ -370,6 +377,10 @@ async function checkAndInstallDotnet10Sdk(verbose = false, addonName = 'csAddon'
370377
const hasDotnet10 = await checkDotnetSdk(verbose);
371378
if (!hasDotnet10) {
372379
console.log('.NET 10 SDK is required for C# addons but was not found.');
380+
console.log('');
381+
console.log('The following command will be run:');
382+
console.log(' ' + getDotnet10SdkWingetCommand());
383+
console.log('');
373384

374385
// Check if we're in an interactive terminal
375386
if (process.stdin.isTTY) {
@@ -422,7 +433,8 @@ function installDotnet10Sdk() {
422433
const { spawn } = require('child_process');
423434

424435
// Use winget to install .NET 10 SDK
425-
const winget = spawn('winget', ['install', '--id', 'Microsoft.DotNet.SDK.10', '--source', 'winget'], {
436+
const command = getDotnet10SdkWingetCommand();
437+
const winget = spawn(command, {
426438
stdio: 'inherit',
427439
shell: true
428440
});
@@ -438,6 +450,14 @@ function installDotnet10Sdk() {
438450
});
439451
}
440452

453+
/**
454+
* Get the winget command line for installing Visual Studio Build Tools
455+
* @returns {string} The winget command line
456+
*/
457+
function getVisualStudioBuildToolsWingetCommand() {
458+
return 'winget install --id Microsoft.VisualStudio.Community --source winget --override "--add Microsoft.VisualStudio.Workload.NativeDesktop --passive --wait"';
459+
}
460+
441461
/**
442462
* Check for Visual Studio Build Tools and offer to install if missing
443463
* @param {boolean} verbose - Enable verbose logging
@@ -446,6 +466,10 @@ async function checkAndInstallVisualStudioBuildTools(verbose = false) {
446466
const hasVisualStudioBuildTools = checkVisualStudioBuildTools();
447467
if (!hasVisualStudioBuildTools) {
448468
console.log('Visual Studio Build Tools are required for C# addons but were not found.');
469+
console.log('');
470+
console.log('The following command will be run:');
471+
console.log(' ' + getVisualStudioBuildToolsWingetCommand());
472+
console.log('');
449473

450474
// Check if we're in an interactive terminal
451475
if (process.stdin.isTTY) {
@@ -536,15 +560,8 @@ function installVisualStudioBuildTools() {
536560
const { spawn } = require('child_process');
537561

538562
// Use winget to install Visual Studio Community with Native Desktop workload
539-
const winget = spawn('winget', [
540-
'install',
541-
'--id',
542-
'Microsoft.VisualStudio.Community',
543-
'--source',
544-
'winget',
545-
'--override',
546-
'--add Microsoft.VisualStudio.Workload.NativeDesktop --passive --wait'
547-
], {
563+
const command = getVisualStudioBuildToolsWingetCommand();
564+
const winget = spawn(command, {
548565
stdio: 'inherit',
549566
shell: true
550567
});

0 commit comments

Comments
 (0)