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.
Related
I'm trying to set default property values such as Configuration Type for all configurations of my Visual Studio project through the .props file for the project, but they aren't being applied. I can set the values of other General properties like Intermediate Directory successfully through the .props file. Using the Configuration Type property as an example, I'm also able to modify this property in the .vcxproj file on a per-configuration basis (Setting the property under a PropertyGroup specifying the configuration using a condition).
When looking at the property page for the .props file in Visual Studio, I suspect that I'm not able to set certain properties for all configurations because there is no corresponding setting.
Property page for the project Property page for the .props file. I've also tried just manually editing the .props file to add this property, but it doesn't get applied:
<ConfigurationType>StaticLibrary</ConfigurationType>
After adding the above line and setting the property value from Visual Studio to , it still defaults To Application (.exe).
Is there a way to set these properties for all configurations in the project so that each individual configuration does not have to specify these properties individually in the .vcxproj file?
The problem is the order in which things are evaluated. If you make a .props which sets ConfigurationType it needs to be imported before the <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> line. VS will still ignore it, showing whatever is configured in the PropertyGroup with Configuration Label, but it will change what gets built.
That's not really nice, and indicates it's also not how you're supposed to do things, so what you could do instead is modify this section of the .vcxproj:
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="my.props" Condition="Exists('my.props')" />
<!-- Supply default in case property sheet not found
and if not passed via /p:MyConfigurationType=xxx or similar -->
<PropertyGroup>
<MyConfigurationType Condition="'$(MyConfigurationType)' == ''">StaticLibrary</MyConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>$(MyConfigurationType)</ConfigurationType>
</PropertyGroup>
I'm not sure it's worth it though. Normally if you want to change the configuration type you select a different configuration/platform combination. The actual type chosen is something you change only once for each project usually, the above is more work.
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.
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.
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.
I've added several directories, libraries such as matlab, opencv, etc to compile my current C file in Visual Studio project.
All my upcoming projects will require the same setup/properties. Do I need to setup my each project's properties individually or I can do something to apply it to all ?
Try using Property Sheets. These can create a single properties file that can be inherited by multiple projects.
Use "View > Other Windows > Property Manager" to bring up the Property Manager. It will show your projects and configurations.
Right click a configuration, and select "Add New Project Property Sheet...". You can name it, and select a location that works for all your projects.
Once created, you can edit its properties just as you would a build configuration.
To use that property sheet as the basis for other projects, just right click the configuration or project, and select "Add Existing Property Sheet...". Browse to where you saved the original sheet, and it will be inherited.
Any changes to the original sheet will be applied to any project that inherits it, unless they are overridden. If you go into properties higher up the chain, properties that override will have bold type for their values. To get them to always use the value in the base sheet, there will be a "inherit from parent or project defaults" option where applicable.
I am using AtmelStudio 6.1, which is built on Visual Studio 2010 (I believe), and yet doesn't have any Property Manager that I can find.
So, the hackish system I use is:
close (or at least unload via the contextual menu) the project whose configuration you want to modify
open its .cproj file (which is XML) in any text editor (VS works nicely),
MAKE A BACKUP COPY OF IT SOMEWHERE ELSE JUST IN CASE,
open the .cproj file of the project whose configuration data you want to copy,
look for the configuration data you want. Configurations are inside of PropertyGroup tags; for example, in my case it looks like
<PropertyGroup Condition=" '$(Configuration)' == 'Preprocess only' ">
for the configuration named "Preprocess only". Copy from the beginning of that tag until the end of the corresponding
</PropertyGroup>
tag.
Paste the block into the destination .cproj, just after other
</PropertyGroup>
tag. Make sure that the name of the configuration is unique in this file. Save.
You're finished. Now open the project normally in VS and you'll be able to select the added configuration.
For Visual Studio 2010+ you can make a Project Template.
If you choose to automatically add the template to Visual Studio in the template creation wizard, when you create/add a new project, the template will appear (after restarting Visual Studio). Projects created with this template will have the same project properties!
To add source code files to the template, the easiest way is to rearrange the source code files in solution-explorer to be in the root (not under any folder). After doing that, THEN generate the template.
Why? Sometimes putting your files under the default Source Code solution-explorer folder (not in file explorer, the .project.filters label) will fail to copy the source file to the template, you'll see "the document cannot be opened. it has been renamed deleted or moved" when you try to use the template and the file you wanted in the template will NOT be in the file explorer.
If you do want solution-explorer folders, you will have to add them manually to the template by unzipping the template folder, making changes, then re-zipping it again.
For example, literally copy and paste the source files you want the template to have in the template folder and edit the .vstemplate file. M$ Doc on template editing.
<TemplateContent>
<!-- put new file references here and/or in your .vcxproj .vcxproj.filters -->
TargetFileName="HelloWorld.cl">HelloWorld.cl</ProjectItem>
<ProjectItem ReplaceParameters="false"
</TemplateContent>
Related questions:
How do I use VS template I created?
How can i load a template I have created in Visual Studio?
How copy visual studio project?
Simply copying and pasting entire projects and solutions is not recommended for complex or shared projects since various GUID s and filenames may overlap - causing bugs.
For MSVS 2017, the process #AaronMK mentioned doesn't work. Instead do the following:
View -> Other Windows -> Property Manager
Add New Property Sheet.
Edit whatever options you want there.
Give it an appropriate name so that you remember it.
Right button on it and hit "Save {myPropertySheet}"
It would be wise to place it alongside the default property sheets and that you can add it whenever you want (by Property Manager -> Add Existing Property Sheet -> Browse to its location). This directory is: C:\Users\{myUsername}\AppData\Local\Microsoft\MSBuild\v4.0
Alternatively you can edit the default property sheets and use these by default. I wouldn't advice it though as they provide a fallback option in case you mess up. So make backups first if editing default files.