Windows Azure Startup task not firing - asp.net

I have a standard ASP.Net application to which I added an Azure Deployment project to deploy to Azure. The app deploys fine to Azure.
I then wanted to extend it to have a startup task.
I added the following to the ServiceDefintion.csdef
<Startup>
<Task commandLine="startup.cmd" executionContext="elevated" taskType="simple"/>
</Startup>
startup.cmd is located in the applications bin folder. I have logging the command file so I can see it is not being executed.
When I deploy the same application to the Compute Emulator on my local machine the startup task executes correctly.
Am I missing something?

Your "startup.cmd" shall not just be in your app BIN folder, but instead in the root folder and marked as "Content" and "Copy to output directory" -> "Copy always". Otherwise it will not get deployed to the Azure.
Another moment to pay attention with Web Applications is that you most probably shall put the bin folder also in the startup task definition. Something like:
<Startup>
<Task commandLine="./bin/startup.cmd" executionContext="elevated" taskType="simple"/>
</Startup>
Hope this helps.

A bit late to the party.
I had this issue as well and for me it was that I had set the Web Role project to the startup project instead of the Azure Cloud Service project. By setting the Azure Cloud Service as the startup project you start the project with the azure emulator, which is needed to get start, run and stop events to work as in your azure environment.

Related

Web Deploy 3.6 automatic backup not created properly when deploying from VS 2015

I am using Web Deploy 3.6 to publish a WebApp from Visual Studio to an IIS 8.5 server. I have configured automatic backup on the server side (based on this article), but when I publish my WebApp from VS2015, my backup only contain two files: archive.xml and system.xml.
If I publish the same WebApp directly from the IIS server, the backup is created as expected.
Because Web Deploy has some known Issues and limitations, I checked that there is no problem with the manifest that is automatically created and used by msdeploy to publish my WebApp.
Here is what is inside my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<IisApp path="C:\Users\niniel\Documents\Visual Studio 2015\Projects\ContosoUniversity\ContosoUniversity\obj\Debug\Package\PackageTmp" managedRuntimeVersion="v4.0" />
<setAcl path="C:\Users\niniel\Documents\Visual Studio 2015\Projects\ContosoUniversity\ContosoUniversity\obj\Debug\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="C:\Users\niniel\Documents\Visual Studio 2015\Projects\ContosoUniversity\ContosoUniversity\obj\Debug\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>
I tried to publish from another computer, just to be sure that this problem is not related to my computer, I had the same problem.
Any help or thought would be appreciated :)
Just in case someone is facing the same problem, I had to give read access to the IIS_IUSRS group on the backup folder to solve my problem.
I would setup the backup by extending the WebDeploy package. This way the server doesn't have to be pre-configured for backups, its just part of the deployment.
http://www.dotnetcatch.com/2016/05/19/extending-the-webdeploy-manifest/
Side note - We stopped taking backups when we started using WebDeploy exclusively for web app deployments. Each WebDeploy package becomes the backup for the next deployment. You should evaluate taking additional backups over time and determine if this process continues to be valuable. At some point, you can hopefully stop.

Can i deploy Azure project on IIS?

I have solution with startup project that have .ccproj format. This is an Azure project that require Azure SDK installed. By default i am able to run it using IIS Express with Azure storage emulator & Azure compute emulator. But when i make some changes i need to recompile entire solution and re-run it. How can i deploy it in IIS server ? Could you advise me alternative deploy method how to run it in simplest way ?
I want to re-compile and attach to process after make some changes in project without restarting IIS Express & Azure emulators, it takes a lot of time.
#DotNetGoose,
should be able to run on IIS but you will need to abstract all the calls that your code read content from RoleEnvironmental and direct them to read from Web.config, and have a copy of corresponding settings in your web.config.
once the abstraction is done, set your web app as default startup project, you should be able to run them as normal web app on iis or iisexpress.

Windows Azure cloud service asp.net config file changes

I have deployed my asp.net web site using cloud service. I have deployed it by publishing from Visual studio.
problem is every time if i have to make changes to web.config, i have to redeploy from visual studio.
Is there anyway we can directly modify from windows azure? I don't want every time developer should involve in this.
Instead of defining your settings in web.config file, you should define them in Service Configuration File (*.cscfg). Then you should be able to change the values from Azure Portal and other means without redeploying your code.
At any cost, stay away from making web.config changes in the deployed code (using RDP or some other means). If for some reason Azure decides to deploy your code in other VM, your changes will be lost. See this thread for more details: Azure Webrole loads old website version after restart.

How to include app pool specification in asp.net deploy script?

I have an MSBuild script that is generating a deployment script for my web app.
Project.build (excerpt)
<MSBuild Projects="xxxxx.sln" Properties="
CreatePackageOnPublish=true;
DeployOnBuild=true;
IncludeIisSettings=true;
IncludeAppPool=true;" >
<Output TaskParameter="TargetOutputs" ItemName="CompiledAssembly" />
</MSBuild>
When this is executed, it does produce a Package folder in the output that contains a deployment .cmd file and associated .zip file.
xxxx.SetParameters.xml (generated)
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="Default Web Site\xxxxx" />
<setParameter name="DefaultConnection-Web.config Connection String"
value=" ... snipped ..." />
</parameters>
As you can see, there is no reference to app pool here. Likewise, there is mention of app pool in the generated xxxx.zip\parameters.xml
When I execute xxxxxx.deploy.cmd /Y, it correctly creates the application in IIS. The problem is, it seems to use the default application pool for the machine. It's a .net 4 app, so if the default is .net 2, the app fails to run.
Is there a way to make the deployment script include an app pool definition so that it won't require manual app pool changes to run?
I did find this question, which seems to be the same. However, as you can see, I've already included the answer from that question, and it has no effect.
If you're trying to deploy a 4.0 app to a 2.0 default app pool without providing an override it will not fail to run but fail to deploy, MSDeploy would simply fail to precreate a virtual app with ERROR_APPPOOL_VERSION_MISMATCH error.
IncludeAppPool is the correct property, but it only tells the packager to include the settings, you have to provide the source, i.e. the "master" virtual app with correct app pool to copy from.
Open project properties and switch from IIS Express to Local IIS, this will enable app pool flag under the package/publish options. I believe you can switch back afterwards, the settings will remain.
This would basically do 2 things, add <IncludeAppPool>true</IncludeAppPool> as well as add the master app under <WebProjectProperties> section. Now when you build or package your source manifest will not have the managedRuntimeVersion requirement but your parameters will now have IIS Web Application Pool Name to customize.
If you want to actually create a new app pool then it gets tricky. I'm not aware of a way to create it during iisApp creation or with some MSBuild flag, but with MSDeploy (the tool behind your .cmd) it would require a dump of your local pool and sync up with appPoolConfig provider, probably as part of your .build script before the .cmd call.
msdeploy -verb:sync -source:appPoolConfig=Foo -dest:package=foo.zip
msdeploy -verb:sync -source:package=foo.zip -dest:appPoolConfig=Foo,computerName=Bar
Keep in mind that without specifying individual appPoolConfig the sync, as it should, would destroy other pools, so do -whatIf first just in case.
You can probably try to merge the archive.xml of your package and the archive.xml with the app pool definition, but I can't image how it would work and what relationship between iisApp and appPoolConfig providers is there.
Edit: You can use manifest provider to combine package or iisApp with appPoolConfig

Where is web.config file when running Azure web role in Compute Emulator?

I created an empty Azure Cloud Service project, then added a web role there. The role project has a web.config file.
When I hit F5 the role is deployed in Compute emulator. I went into the folder where role binaries are deployed - there's no web.config file there.
What's happening? Is that because I didn't set "copy always" on web.config file? What web.config does my role use?
If your role is configured for Full IIS mode (for those unaware of the difference between Hosted Web Core and Full IIS, see this blog post), the compute emulator should deploy the web role to IIS where it can be viewed in IIS Manager. On my machine (I'm running Azure SDK 1.5), the deployed web role's physical path is my source code directory.
I think web.config is compiled into your assembly as content in your development environment, and is not directly accessible like in staging/prod. You don't need to use Copy Always, if its marked as Content its all you need. You can use Environment.CurrentDirectory to see your web root path.
Even though the preferred way of storing configuration in Windows Azure applications is in the ServiceConfiguration.cscfg file, there are still many cases when you may want to use a normal .NET config file - especially when configuring .NET system components or reusable frameworks. In particular whenever you use Windows Azure diagnostics you need to configure the DiagnosticMonitorTraceListener in a .NET config file.
When you create your web role project, Visual Studio creates a web.config file for your .NET configuration. While your web application can access this information, your RoleEntryPoint code cannot-because it's not running as a part of your web site. As mentioned earlier, it runs under a process called WaIISHost.exe, so it expects its configuration to be in a file called WaIISHost.exe.config. Therefore, if you create a file with this name in the your web project and set the "Copy to Output Directory" property to "Copy Always" you'll find that the RoleEntryPoint can read this happily. This is one of the only cases I can think of where you'll have two .NET configuration files in the same project!
All info is from Azure Team Blog and I have used this solution successfully- http://blogs.msdn.com/b/windowsazure/

Resources