|
29 | 29 | <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" /> |
30 | 30 | </ItemGroup> |
31 | 31 |
|
| 32 | + <!-- |
| 33 | + Cross-platform node/npm invocation. |
| 34 | + On Windows, MSBuild inherits PATH from the OS (where the Node installer |
| 35 | + usually places node), so we call the executables directly. |
| 36 | + On Unix (Linux/macOS), version managers like nvm / fnm / volta only inject |
| 37 | + node into PATH inside interactive shells (.zshrc / .bashrc). MSBuild spawns |
| 38 | + a non-interactive process, so we route the command through the user's |
| 39 | + default $SHELL with -i -l -c to source those rc files. |
| 40 | + --> |
| 41 | + <PropertyGroup> |
| 42 | + <_NodeShellPrefix Condition=" '$(OS)' != 'Windows_NT' ">"$SHELL" -ilc </_NodeShellPrefix> |
| 43 | + <_NodeVersionCommand Condition=" '$(OS)' == 'Windows_NT' ">node --version</_NodeVersionCommand> |
| 44 | + <_NodeVersionCommand Condition=" '$(OS)' != 'Windows_NT' ">$(_NodeShellPrefix)"node --version"</_NodeVersionCommand> |
| 45 | + <_NpmInstallCommand Condition=" '$(OS)' == 'Windows_NT' ">npm install</_NpmInstallCommand> |
| 46 | + <_NpmInstallCommand Condition=" '$(OS)' != 'Windows_NT' ">$(_NodeShellPrefix)"npm install"</_NpmInstallCommand> |
| 47 | + </PropertyGroup> |
| 48 | + |
32 | 49 | <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') "> |
33 | 50 | <Message Importance="high" Text="Current node version:" /> |
34 | 51 |
|
35 | | - <Exec Command="node --version" ContinueOnError="true"> |
| 52 | + <Exec Command="$(_NodeVersionCommand)" ContinueOnError="true"> |
36 | 53 | <Output TaskParameter="ExitCode" PropertyName="ErrorCode" /> |
37 | 54 | </Exec> |
38 | 55 |
|
39 | 56 | <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." /> |
40 | 57 |
|
41 | 58 | <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." /> |
42 | 59 |
|
43 | | - <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> |
| 60 | + <Exec WorkingDirectory="$(SpaRoot)" Command="$(_NpmInstallCommand)" /> |
44 | 61 | </Target> |
45 | 62 | </Project> |
0 commit comments