@@ -63,6 +63,8 @@ class MyGenerator extends yeoman.Base {
6363 if ( isWindows ) {
6464 assertNpmVersionIsAtLeast ( '3.0.0' ) ;
6565 }
66+
67+ assertDotNetSDKVersionIsAtLeast ( '1.0.0' ) ;
6668 }
6769
6870 prompting ( ) {
@@ -99,6 +101,7 @@ class MyGenerator extends yeoman.Base {
99101 this . _answers . templateConfig = templateConfig ;
100102 this . _answers . namePascalCase = toPascalCase ( answers . name ) ;
101103 this . _answers . projectGuid = this . options [ 'projectguid' ] || uuid . v4 ( ) ;
104+ this . _answers . sdkVersion = getDotNetSDKVersion ( ) ;
102105
103106 done ( ) ;
104107 } ) ;
@@ -199,6 +202,27 @@ function assertNpmVersionIsAtLeast(minVersion: string) {
199202 }
200203}
201204
205+ function assertDotNetSDKVersionIsAtLeast ( minVersion : string ) {
206+ const runningVersion = getDotNetSDKVersion ( ) ;
207+ if ( ! runningVersion ) {
208+ console . error ( 'Could not find dotnet tool on system path. Please install dotnet core SDK then try again.' ) ;
209+ console . error ( 'Try running "dotnet --version" to verify you have it.' ) ;
210+ process . exit ( 1 ) ;
211+ } else if ( ! semver . gte ( runningVersion , minVersion , /* loose */ true ) ) {
212+ console . error ( `This generator requires dotnet SDK version ${ minVersion } or later. You have version ${ runningVersion } ` ) ;
213+ console . error ( 'Please update your dotnet SDK then try again. You can run "dotnet --version" to check your version.' ) ;
214+ process . exit ( 1 ) ;
215+ }
216+ }
217+
218+ function getDotNetSDKVersion ( ) {
219+ try {
220+ return execSync ( 'dotnet --version' ) . toString ( ) . replace ( / \r | \n / g, '' ) ;
221+ } catch ( ex ) {
222+ return null ;
223+ }
224+ }
225+
202226function rewritePackageJson ( contents , includeTests ) {
203227 if ( ! includeTests ) {
204228 // Delete any test-specific packages from dependencies and devDependencies
0 commit comments