Windows Azure - Virtual Application - asp.net-mvc-3

I have one web application and virtual application in Azure. They are separate projects in VS2010 and I have added them to one solution with one Azure deployment project.
I have created multiple web.configs to control parameters, ie web.debug.config etc.
When I publish to azure I specify debug which works for the main application but the virtual application is pointing to the web.config not the variants. How do I correct this please?
Many Thanks,
Steve.

Solution
The solution that worked for me from http://blog.hill-it.be/2011/03/07/no-web-config-transformation-in-local-azure/:
To fix this, unload your Azure project, open the project file for edit and add the tag [under the corresponding PropertyGroup]:
<Project ...>
<PropertyGroup>
...
<packagewebrole>true</packagewebrole>
Workaround
There's also a workaround, it will work for a local development, but not for continuous integration (or at least you will have to find another trick).
In your service definition file add a new Site section:
<Site name="AnotherSite" physicalDirectory="c:\AnotherSite">
<Bindings>
<Binding name="APIEndpoint" endpointName="AnotherSiteEndpoint" />
</Bindings>
</Site>
Add a new endpoint to match the code above (any port works):
<InputEndpoint name="AnotherSiteEndpoint" protocol="http" port="623" />
Go to your web-project --> right-click --> Publish... --> FTP --> Location = "c:\AnotherSite"
Press F5 and go to http://127.0.0.1:623
It should work.

Web application always uses web.config. If you want to use debug / release versions you have to create web.config Transformation. In this case web.config is transformed at build time using selected build target.

Related

Modifying web.config for development and production environments

I have a webApi project and after deployment to Dev environment I need to edit web.config and change connection to database from production configuration to development configuration and back if I need deployment to prod.
How can I automatically set webconfig for selected dev or prod in the release or debug I use in my project?
To specify the changes that you want to make in Web.config files, you use transform files. A transform file is associated with a build configuration.
If you want to create a transform file for a custom build configuration that does not exist, create the build configuration first by using Configuration Manager.
You can open Configuration Manager by selecting it from the Build menu.
In Solution Explorer, expand the application Web.config file.
If any transform files have already been created, the Web.config file is displayed in Solution Explorer with a symbol indicating that it can be expanded, and the transform files are shown when you expand the Web.config file.
The build configuration that a transform is for is indicated by a string in the file name. For example, a transform file for the Debug build configuration is named Web.Debug.config.
If no transform file exists for the build configuration that you want to specify settings for, in Solution Explorer, right-click the Web.config file and then click Add Config Transforms.
Open the transform file for the build configuration that you want to work with.
Edit the transform file to specify the changes that should be made to the deployed Web.config file when you deploy by using that build configuration.
The default transform file includes comments that show how to code some common transforms.
The following example shows how to use the Match locator and the SetAttributes transform attribute. The Match locator attribute identifies the add element in the connectionStrings section as the element to change. The SetAttributes transform attribute specifies that this element's connectionString attribute should be changed to "ReleaseSQLServer".
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="ReleaseSQLServer"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
Save and close the transform file.
When you deploy the Web application by using the selected build configuration and by using either a deployment package or one-click publish, the Web.config file is transformed according to your specifications.

Using transformed Web.config with IIS Express during debug

I have a Visual Studio application that has multiple Solution Configurations. There is a Web.config transform file for each configuration. For example, Web.Debug.config, Web.Release.config, etc.
We also have a couple of developers working on this project that have nonstandard SQL Express instance names due to the way they installed SQL Express and rather than having them continually editing Web.Debug.config to run in their environment I have setup a Solution Configuration for each of them and added the following to the very bottom of the .csproj file. This code does work in that it triggers the creation of Web.config and MyWebApp.dll.config in the VS /obj/Debug-DeveloperName/ folder.
The transformed .config files are perfect, but IIS Express still uses the root Web.config (not transformed).
Is there a way to get IIS Express to use these transformed Web.config files while debugging locally?
<UsingTask
TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target
Name="AfterCompile"
Condition="exists('Web.$(Configuration).config')">
<!-- Generate transformed config in intermediate directory -->
<TransformXml
Source="Web.config"
Destination="$(IntermediateOutputPath)$(TargetFileName).config"
Transform="Web.$(Configuration).config"
/>
</Target>
Using the web application's Web.Debug.Config works for most of us, but not all.
There must be a way of getting IIS Express to use the transformed Web.Debug-DeveloperName.config during local debug?
Does the transformed Web.config have to be copied into a different folder?
I faced this problem before and I found a solution. Unfortunately, the solution is not based on forcing IIS to use different name of the config, but if you follow steps below, you will just select the configuration and run you app (which is ewhat you need I think). The Web.config transform will occur before build and it will replace the original Web.config by the transformad one. Then, when the deployment (to local IIS Express) begins, it will already use the transformed one.
Here is step by step how I did this in one project (VS2012):
Right click on the project and select Unload
Right click on it again and select Edit
Go to the bottom of the file and append the follwing to the right over the "</Project>" tag (it will be last item)
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">
<TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>
The condition there is to prevent duplicate transformation when publishing.
Save the file, right click on it and select Reload
Now, everytime you run a build, your Web.config will be transformed according to selected configuration.

The 'DefaultConnection-Web.config Connection String' argument cannot be null or empty

When I deploy my project with "Publish as Azure WebJob" using Visual Studio, I get the error in the title.
Fixed by removing the following markup from the .pubxml file. You must exit/restart VS after removing the markup (or VS will add it back in).
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String" />
</ItemGroup>
Reason of the problem is one of the followings:
Change the name of the connection string in the web.config.
Add a new connection string in the web.config
Solution
Select the website project, right-click on it, and click publish.
Press the settings link and from the pop-up window select the 'Settings' Tab
Uncheck the use this connection string at runtime from all your connection strings.
Click the Save button to close the window. (No need to restart Visual Studio)
Try to publish the website again, and it should publish without a problem.
You can reconfigure the settings as it was previously, the unchecking just triggers VS to regenerate the .pubxml file, So you are not forced to change your settings at all.
NOTE
I am using VS 2017 (and according to the comments this also work in Visual Studio 2013)
Just for Note
After I did the previous steps, I noticed that the .pubxml file changed automatically. here is the difference which has been made (automatically without any interference from me)
So I think this is a better way because it is easier for the developer and also it let the visual studio to solve its problems himself, without forcing it into a specific thing.
Create a Parameters.xml file in the Project root with the following content:
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="DefaultConnection-Web.config Connection String"
description="DefaultConnection"
defaultValue="Server=tcp:x.database.windows.net,1433;Database=x_db;User ID=x#y;Password=z;Trusted_Connection=False;etc." tags="" />
</parameters>
All the other missing config elements can be added here as well.
I have Visual Studio 2015 Update 3 and i was facing the same issue. The solution i found that is working for me is the following:
1) Open *.pubxml file under properties -> publish profiles.
2) Look for the Path attribute under PublishDatabaseSettings section:
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="eRecall.ETL.Models.erecallContext" Order="1" Enabled="False">
<Destination Path="" />
<Object Type="DbCodeFirst">
<Source Path="DBContext" DbContext="eRecall.ETL.Models.erecallContext, eRecall.ETL" />
</Object>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
3) Set Path attribute value to the following:
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="eRecall.ETL.Models.erecallContext" Order="1" Enabled="False">
<Destination Path="{deployment connection string}" />
<Object Type="DbCodeFirst">
<Source Path="DBContext" DbContext="eRecall.ETL.Models.erecallContext, eRecall.ETL" />
</Object>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
4) Delete the existing webjob deployment in Azure Job Collection Scheduler.
5) Re-Deploy the webjob, Re-run the webjob from the scheduler and it starts working with no issues!
Hope this helps.

Visual Studio 2013 Website Project - Change Configuration in Configuration Manager

I have Website Project in Visual Studio 2013. I have two Publishing Profiles, one for staging and the other for production. In Configuration Manager, I can create new Active Solution Configurations but cannot add new Configurations to my drop-down, Debug is the only option.
So now when I attempt to Publish using my production profile, the web.config is getting transformed by both the Web.Debug.Config and my web.Production.Config.
How do I add new Configurations to the dropdown?
How do I add new Configurations to the dropdown?
You can't. At least not for the purpose you need to use these new configurations for.
I'll make the assumption that you really need to know this:
How can I publish a web site without the debug flag being applied to the web.config by the debug transform?
This is already happening, just in a confusing way.
When you publish the site using the Publish Web Site wizard it applies the appropriate transforms to the web.config. In your case, Web.Debug.Config and Web.Production.Config.
And now for the confusing part:
By default, web.debug.config actually removes the debug attribute from the web.config.
<compilation xdt:Transform="RemoveAttributes(debug)" />
This happens for legacy reasons to do with the missing Web Site project file and the underlying build tools.
If you want to stop the debug transformation being applied and you have no custom configuration in it, you can delete web.debug.config. Just be sure to add
<compilation xdt:Transform="RemoveAttributes(debug)" />
inside the <system.web> element of each of your environment specific transforms (web.Production.Config, etc).
My recommendation is:
Leave web.debug.config untouched. In its default state.
Create a publish profile for each environment.
Add a transform for each publish profile (web.<configuration>.config)
Put any environment specific configuration into the appropriate transform file.
To get my publish settings working the way I wanted I had to:
Return web.debug.config back to it's default contents (I had some transforms in here that I was using for my staging environment)
For every publish profile in /App_Data/PublishProfiles/, right click and select Add Config Transform to create a new config file at the root of the site (note that it will not be nested under the default web.config unless the profile is titled debug or release, kinda odd if you ask me)
Add any relevant transforms to each of these new configs
Since all publish profiles in a website project seem to be stuck on a debug configuration, there was no way for me to avoid web.debug.config transforming my default web.config. With this solution, we simply don't use web.config for publish specific transforms.
I'd like to credit Chris O'Neill for his helpful, if verbose, answer that clued me into this solution.
You can modify/create the configuration of the project FSUResearch manually. The steps are:
In solution explorer:
Right click on the project -> Unload project -> Right click on FSUResearch (unavailable) -> Click on Edit FSUResearch.csproj
In this file you will see many 'PropertyGroup' tags. These PropertyGroups consists of different combinations of configuration and platform. So create a new PropertyGroup and give your own project configurations. Make sure to give the project configuration name that is already a solution configuration name (Understand build configurations).
For example:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Production|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Save the changes and then right click on the .csproj file again and reload the project.

Visual Studio 2010 : Can't change target. Gives TargetFrameworkMoniker Error

I have a console application which has target .NET 2.0
It is very short but full of unsafe code.
I converted it to VS 2010. I run it OK.
When I try to change "target framework" in properties to 3.5 or 4.0 it shows message box:
TargetFrameworkMoniker: Error parsing application configuration file at line 0. XML document must have a top level element.
the target then stays 2.0 anyway.
This happened to me because my project file was marked as "Read Only" in its properties. Changed it, and it was fine.
It also could be caused by read-only app.config/web.config
Found the solution. Simply opened app.config in text pad (it was empty for some reason) and pasted:
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
For me the problem was the web.config file located outside of the project directory.
I moved it back in, and was able to change the target framework.
I have same issue. I solved it by removing write protected attribute of web.config file. It was read only earlier.
For me, my project was using a web.config file that was a linked file back to a web.config in another project. I removed the link, changed the target, then added the link back.
I faced this problem , i solved it by click app.config to open it and leave it ,then go to properties and upgrade .NET version
I was trying to retarget from .NET 4.5.2 to .NET 4.5 In my app.config, I had to change
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
to
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
before the project properties page would let me retarget.

Resources