I tried several solutions and here is the simplest I personally found.
Dan pointed out in the comments that the original post belongs to Oleg Sych—thanks, Oleg!
Here are the instructions:
1. Add an XML file for each configuration to the project.
Typically you will have Debug
and Release
configurations so name your files App.Debug.config
and App.Release.config
. In my project, I created a configuration for each kind of environment, so you might want to experiment with that.
2. Unload project and open .csproj file for editing
Visual Studio allows you to edit .csproj files right in the editor—you just need to unload the project first. Then right-click on it and select Edit <ProjectName>.csproj.
3. Bind App.*.config files to main App.config
Find the project file section that contains all App.config
and App.*.config
references. You'll notice their build actions are set to None
and that's okay:
<None Include="App.config" />
<None Include="App.Debug.config" />
<None Include="App.Release.config" />
Next, make all configuration-specific files dependant on the main App.config
so Visual Studio groups them like it does designer and code-behind files.
Replace XML above with the one below:
<None Include="App.config" />
<None Include="App.Debug.config" >
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Release.config" >
<DependentUpon>App.config</DependentUpon>
</None>
4. Activate transformations magic (still necessary for Visual Studio versions such as VS2019)
In the end of file after
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
and before final
</Project>
insert the following XML -- please note there are two steps for the proper transformation to occur:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="BeforeBuild" Condition="Exists('App.$(Configuration).config')">
<!-- Generate transformed app config and replace it: will get the <runtime> node and assembly bindings properly populated -->
<TransformXml Source="App.config" Destination="App.config" Transform="App.$(Configuration).config" />
</Target>
<Target Name="AfterBuild" Condition="Exists('App.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory: this will transform sections such as appSettings -->
<TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Now you can reload the project, build it and enjoy App.config
transformations!
FYI
Make sure that your App.*.config
files have the right setup like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--magic transformations here-->
</configuration>
Best Answer
I interpret the problem as follows: the file
DotNetConfig.xsd
has wrong (or not full) definition of the<startup>
element. Line 230 of allDotNetConfig.xsd
,DotNetConfig35.xsd
,DotNetConfig30.xsd
andDotNetConfig20.xsd
files containsOn the other side Microsoft describes the startup settings schema as a non-empty element. So I suggest to replace the above line in
DotNetConfig.xsd
and in allDotNetConfigXX.xsd
files from the%ProgramFiles%\Microsoft Visual Studio 10.0\Xml\Schemas
directory (or%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas
directory on 64-bit systems) with the following lines:After such modification and restarting of Visual Studio 2010 you will not have the warnings which you described. Of course one can define the schema of all attributes or elements in a more detailed manner (especially if we find more detailed documentation of the
<startup>
section), but I want to describe the reason of the problem only and one way to fix it.By the way the choice between
DotNetConfig.xsd
,DotNetConfig35.xsd
and otherDotNetConfigXX.xsd
files will be done based on the contents of thecatalog.xml
file from the same directory, the schema of which is described here. The standard version of thecatalog.xml
file contains the following lines:So all files having
.config
extension will be interpreted by Visual Studio as files with the XSD schema described by one from above files.