diff --git a/README.md b/README.md index 2d37bd7..0d028bf 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,26 @@ ## Music store application +###Getting Started + +The first thing we need to do is setup the tools required to build and run an application. + +* Clone the repository +* On the command line execute ```kvm setup``` +* This command will download the latest version of the SDK and put it on your path so that you can run the rest of the commands in the readme. If you want to know more about what this is doing then you can read the [KVM page](https://github.com/aspnet/Preview/wiki/version-manager) of the wiki. +* If you already have ```kvm``` installed on the machine ignore above steps. + ### Run the application: 1. Run build.cmd to restore all the necessary packages and generate project files 2. Open a command prompt and cd \src\\ 3. [Helios]: 4. Helios.cmd to launch the app on IISExpress (Application started at URL http://localhost:5001/). 4. [SelfHost]: - 5. Run Selfhost.cmd (This runs k web - Application started at URL http://localhost:5002/) + 5. Run ```k web``` (Application started at URL http://localhost:5002/) 5. [CustomHost]: - 6. Run CustomHost.cmd (This hosts the app in a console application - Application started at URL http://localhost:5003/) + 6. Run ```k run``` (This hosts the app in a console application - Application started at URL http://localhost:5003/) + +### Switching between Desktop CLR and CoreCLR: +By default the app runs on desktop CLR. To switch to run the app on CoreCLR set environment variable ```SET TARGET_FRAMEWORK=k10```. To switch back to desktop CLR ```SET TARGET_FRAMEWORK=``` to empty. ### Adding a new package: 1. Edit the project.json to include the package you want to install diff --git a/kvm.cmd b/kvm.cmd new file mode 100644 index 0000000..7b73752 --- /dev/null +++ b/kvm.cmd @@ -0,0 +1,187 @@ +@ECHO OFF +IF "%1"=="" ( + CALL :cmd_help +) ELSE ( + CALL :cmd_%1 %* + IF ERRORLEVEL 1 CALL:cmd_help +) +GOTO:EOF + + +:cmd_setup +SET "_KVM_PATH=%USERPROFILE%\.k\" +SET "_TEMP_PATH=%PATH%" + +IF /I NOT "%~dp0"=="%_KVM_PATH%" ( + IF NOT EXIST "%_KVM_PATH%" MKDIR "%_KVM_PATH%" + COPY "%~f0" "%_KVM_PATH%kvm.cmd" +) + +:PARSE_START +@IF "%_TEMP_PATH%"=="" GOTO PARSE_END +@FOR /F "tokens=1* delims=;" %%a in ("%_TEMP_PATH%") Do @IF "%%a"=="%_KVM_PATH%" GOTO:end_setup +@FOR /F "tokens=1* delims=;" %%a in ("%_TEMP_PATH%") Do @SET _TEMP_PATH=%%b +@GOTO PARSE_START +:PARSE_END + +SET "PATH=%PATH%;%_KVM_PATH%" +powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Environment]::SetEnvironmentVariable('PATH',[Environment]::GetEnvironmentVariable('PATH','user')+';%_KVM_PATH%','user');" + + +:end_setup +CALL "%_KVM_PATH%kvm.cmd" upgrade +@ECHO Running crossgen, see crossgen.log for results +CALL "%_KVM_PATH%k.cmd" crossgen >crossgen.log 2>crossgen.err.log +SET _KVM_PATH= +SET _TEMP_PATH= +GOTO:EOF + + +:cmd_upgrade +CALL:cmd_install install +CALL:cmd_alias alias default %_KVM_VERSION% +GOTO:EOF + + +:cmd_install +IF NOT EXIST "%~dp0.nuget\NuGet.exe" ( + IF NOT EXIST "%~dp0.nuget" MKDIR "%~dp0.nuget" + ECHO Downloading latest version of NuGet.exe... + @powershell -NoProfile -ExecutionPolicy unrestricted -Command "((new-object net.webclient).DownloadFile('https://nuget.org/nuget.exe', '%~dp0.nuget\NuGet.exe'))" +) + +IF NOT EXIST "%~dp0.nuget\NuGet.config" ( +echo ^ >"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +echo ^ >>"%~dp0.nuget\NuGet.config" +) + +IF "%2"=="" ( + echo Finding latest version + FOR /f "tokens=1,2" %%G in ('"%~dp0.nuget\NuGet.exe" list ProjectK -Prerelease -ConfigFile %~dp0.nuget\NuGet.config') DO ( + IF "%%G"=="ProjectK" ( + SET _KVM_VERSION=%%H + ) + ) +) ELSE ( + SET "_KVM_VERSION=%2" +) + +ECHO Downloading version %_KVM_VERSION% +"%~dp0.nuget\NuGet.exe" install ProjectK -Version %_KVM_VERSION% -OutputDirectory "%~dp0packages" -ConfigFile "%~dp0.nuget\NuGet.config" + +CALL:cmd_use use %_KVM_VERSION% +GOTO:EOF + + +:cmd_use +IF NOT EXIST "%~dp0k.cmd" ( + ECHO @CALL %%~dp0kvm.cmd k %%* >%~dp0k.cmd +) +IF EXIST "%~dp0alias\%2.txt" ( + FOR /F %%G IN (%~dp0alias\%2.txt) DO ( + ECHO Setting _KVM_VERSION to '%%G' + SET "_KVM_VERSION=%%G" + ) +) ELSE ( + IF NOT EXIST "%~dp0packages\ProjectK.%2\tools\k.cmd" ( + ECHO Version '%2' not found. + ECHO You may need to run 'kvm install %2' + GOTO:EOF + ) + ECHO Setting _KVM_VERSION to '%2' + SET "_KVM_VERSION=%2" +) +GOTO:EOF + + +:cmd_alias +IF NOT EXIST "%~dp0alias" ( + MKDIR "%~dp0alias" +) +IF "%3"=="" ( + IF "%2"=="" ( + DIR "%~dp0alias" /b + ) ELSE ( + ECHO Alias '%2' is + TYPE "%~dp0alias\%2.txt" + ) +) ELSE ( + IF NOT EXIST "%~dp0packages\ProjectK.%3\tools\k.cmd" ( + ECHO Version '%3' not found. + ECHO You may need to run 'kvm install %3' + GOTO:EOF + ) + + ECHO Setting alias '%2' to '%3' + ECHO %3>%~dp0alias\%2.txt +) +GOTO:EOF + + +:cmd_list +dir /b "%~dp0packages\ProjectK*" +GOTO:EOF + + +:cmd_k +@REM find k.cmd in local paths + +@REM read _KVM_VERSION.txt if _KVM_VERSION not set +IF "%_KVM_VERSION%" == "" ( + FOR /F %%G IN (%~dp0alias\default.txt) DO ( + SET "_KVM_VERSION=%%G" + ) +) +IF NOT EXIST "%~dp0packages\ProjectK.%_KVM_VERSION%\tools\k.cmd" ( + ECHO Version '%_KVM_VERSION%' not found. + ECHO You may need to run 'kvm install %_KVM_VERSION%' +) ELSE ( + CALL "%~dp0packages\ProjectK.%_KVM_VERSION%\tools\k.cmd" %2 %3 %4 %5 %6 %7 %8 %9 +) +GOTO:EOF + + +:cmd_help +ECHO kvm ^ [args...] +ECHO k version manager +ECHO . +ECHO kvm help +ECHO displays this help +ECHO . +ECHO kvm upgrade +ECHO install latest k version and make it the default +ECHO . +ECHO kvm install ^ +ECHO install and use specific k version +ECHO . +ECHO kvm list +ECHO list installed k versions +ECHO . +ECHO kvm use ^^|^ +ECHO use a version or alias within the current command prompt +ECHO . +ECHO kvm alias ^ ^ +ECHO create alias to a specific version +ECHO alias names may be passed to 'kvm use ^' +ECHO the alias 'default' determines the default k version +ECHO when kvm use is not called +ECHO . +ECHO kvm alias ^ +ECHO show the version of an alias +ECHO . +ECHO kvm alias +ECHO list aliases +ECHO . + +GOTO:EOF + + diff --git a/src/MusicStore/CustomHost.cmd b/src/MusicStore/CustomHost.cmd deleted file mode 100644 index 83dbf25..0000000 --- a/src/MusicStore/CustomHost.cmd +++ /dev/null @@ -1,11 +0,0 @@ -REM run on k10 by default. Assign it to an empty value to run on desktop CLR. -SET TARGET_FRAMEWORK=k10 - -REM Selfhost does not need this bin folder -rmdir /S /Q bin - -REM Figure out path to K.cmd - -FOR /F %%j IN ('dir /b /o:-d ..\..\packages\ProjectK*') do (SET K_CMD_PATH=..\..\packages\%%j\tools\k.cmd) -echo Found k.cmd at %K_CMD_PATH%. Starting the self host application -%K_CMD_PATH% run server.urls=http://localhost:5003 \ No newline at end of file diff --git a/src/MusicStore/SelfHost.cmd b/src/MusicStore/SelfHost.cmd deleted file mode 100644 index b752619..0000000 --- a/src/MusicStore/SelfHost.cmd +++ /dev/null @@ -1,11 +0,0 @@ -REM run on k10 by default. Assign it to an empty value to run on desktop CLR. -SET TARGET_FRAMEWORK=k10 - -REM Selfhost does not need this bin folder -rmdir /S /Q bin - -REM Figure out path to K.cmd - -FOR /F %%j IN ('dir /b /o:-d ..\..\packages\ProjectK*') do (SET K_CMD_PATH=..\..\packages\%%j\tools\k.cmd) -echo Found k.cmd at %K_CMD_PATH%. Starting the self host application -%K_CMD_PATH% web \ No newline at end of file diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index a874901..37be3af 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -1,4 +1,9 @@ { + "name": "MusicStore", + "authors": [ + "Microsoft" + ], + "description": "Music store application on K", "version": "0.1-alpha-*", "dependencies": { "Helios": "0.1-alpha-*", @@ -34,7 +39,8 @@ "Microsoft.AspNet.Logging": "0.1-alpha-*" }, "commands": { - "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5002" + "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5002", + "run": "run server.urls=http://localhost:5003" }, "configurations": { "net45": {