Azure
supports the .NET framework 4.6 and less. So if your application build around
higher version of dot net like 4.6.1, 4.6.2 you need to install your target framework
on the Azure Cloud Service Role.
Please
follow the bellow steps to install the .Net Framework on the Azure cloud
service web role.
1.
Add the .NET installer to project
2.
Define startup tasks for roles
1.
Add the .NET Installer to Project:
i. Download .NET 4.6.1 Web Installer
from here
ii. Create New Folder inside web
role. Rename it as ‘bin’. Copy this installer in this folder.
iii. Do this same for all role if more
than one role is present in cloud service.
iv. For worker role: don’t create the
folder just directly add existing item to it and select the installer.
2.
Define Startup Task and Add Install script:
A) Add Install script
I.
Startup
Task will run the web installer form the project to your role VM.
II.
Copy
the Below Code. Don’t change anything from it.
III.
Save
it in notepad File, Rename the File as ‘install.cmd’. Keep the extension of the
file as .cmd. Copy this file to the ‘bin’ folder created inside the role.
IV.
Your
folder structure will look like this :
I.
Installer
Code to copy in file is :
set netfx="NDP461"
set timehour=%time:~0,2%
set timestamp=%date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour:
=0%%time:~3,2%
set "log=install.cmd started
%timestamp%."
if %ComputeEmulatorRunning%=="true"
goto exit
see an out of disk space error *****
set TMP=%PathToNETFXInstall%
set TEMP=%PathToNETFXInstall%
if %netfx%=="NDP462" goto
NDP462
if %netfx%=="NDP461" goto
NDP461
if %netfx%=="NDP46" goto
NDP46
set "netfxinstallfile=NDP452-KB2901954-Web.exe"
set netfxregkey="0x5cbf5"
goto logtimestamp
:NDP46
set "netfxinstallfile=NDP46-KB3045560-Web.exe"
set netfxregkey="0x6004f"
goto logtimestamp
:NDP461
set "netfxinstallfile=NDP461-KB3102438-Web.exe"
set netfxregkey="0x6040e"
goto logtimestamp
:NDP462
set "netfxinstallfile=NDP462-KB3151802-Web.exe"
set netfxregkey="0x60632"
:logtimestamp
REM ***** Setup LogFile with timestamp *****
md "%PathToNETFXInstall%\log"
set startuptasklog="%PathToNETFXInstall%log\startuptasklog-%timestamp%.txt"
set netfxinstallerlog="%PathToNETFXInstall%log\NetFXInstallerLog-%timestamp%"
echo %log% >> %startuptasklog%
echo Logfile generated at: %startuptasklog%
>> %startuptasklog%
echo TMP set to: %TMP% >> %startuptasklog%
echo TEMP set to: %TEMP% >> %startuptasklog%
echo Checking if .NET (%netfx%) is
installed >> %startuptasklog%
set /A netfxregkeydecimal=%netfxregkey%
set foundkey=0
FOR /F "usebackq skip=2
tokens=1,2*" %%A in (`reg query
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework
Setup\NDP\v4\Full" /v Release 2^>nul`) do @set /A foundkey=%%C
echo Minimum required key: %netfxregkeydecimal%
-- found key: %foundkey% >> %startuptasklog%
if %foundkey% GEQ %netfxregkeydecimal% goto
installed
echo Installing .NET with commandline:
start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% /chainingpackage "CloudService Startup
Task" >> %startuptasklog%
start /wait %~dp0%netfxinstallfile% /q
/serialdownload /log %netfxinstallerlog% /chainingpackage "CloudService
Startup Task" >> %startuptasklog% 2>>&1
if %ERRORLEVEL%== 0 goto installed
echo .NET installer exited with code %ERRORLEVEL% >> %startuptasklog%
if %ERRORLEVEL%== 3010 goto restart
if %ERRORLEVEL%== 1641 goto restart
echo .NET (%netfx%) install failed with Error Code %ERRORLEVEL%. Further
logs can be found in %netfxinstallerlog% >> %startuptasklog%
:restart
echo Restarting to complete .NET (%netfx%)
installation >> %startuptasklog%
EXIT /B %ERRORLEVEL%
:installed
echo .NET (%netfx%) is installed >>
%startuptasklog%
:end
echo install.cmd completed: %date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour:
=0%%time:~3,2% >> %startuptasklog%
:exit
EXIT /B 0
B) Set Startup Task in Service Definition
Add the below code to the ServiceDefination.csdef
<LocalResources>
<LocalStorage name="NETFXInstall" sizeInMB="1024"
cleanOnRoleRecycle="false" />
</LocalResources>
<Startup>
<Task commandLine="install.cmd" executionContext="elevated"
taskType="simple">
<Environment>
<Variable name="PathToNETFXInstall">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='NETFXInstall']/@path"
/>
</Variable>
<Variable name="ComputeEmulatorRunning">
<RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated"
/>
</Variable>
</Environment>
</Task>
</Startup>
Your service Definition will look
like this
this has helped supporting multiple advanced features of 4.6.1 to be used on azure roles when this framework was not supported.
ReplyDelete
ReplyDeleteThis blog gives very important info about .Net Thanks for sharing
.Net Online Training
It has been a long time since I've read anything so informative and compelling. I'm waiting for the next article from the writer. Thank you.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery