1, create the corresponding configuration of the app. Config file, such as: App.Debug.config, App.Release.config.
2. Edit the project file and modify the build action of the App.*.config file to content, as follows:
<ContentInclude= "app. Config" /> <ContentInclude= "App.Debug.config"> <DependentUpon>App.</DependentUpon> </Content> <ContentInclude= "App.Publish.config"> <DependentUpon>App.</DependentUpon> </Content> <ContentInclude= "App.Release.config"> <DependentUpon>App.</DependentUpon> </Content>
3. Add the following configurations before </Project> tags:
<UsingTaskTaskName= "TransformXML"assemblyfile= "$ (msbuildextensionspath) \microsoft\visualstudio\v10.0\web\microsoft.web.publishing.tasks.dll" /> <TargetName= "Aftercompile"Condition= "exists (' app.$ (Configuration). config ')"> <TransformXMLSource= "app. Config"Destination= "$ (intermediateoutputpath) $ (targetfilename). config"Transform= "app.$ (Configuration). config" /> <ItemGroup> <AppconfigwithtargetpathRemove= "app. Config" /> <AppconfigwithtargetpathInclude= "$ (intermediateoutputpath) $ (targetfilename). config"> <TargetPath>$ (targetfilename). config</TargetPath> </Appconfigwithtargetpath> </ItemGroup> </Target>
Reload the project to see the same effect as the App. Config and Web. config.
If you do not want to use various xdt syntax, you can specify the configuration's app. Config directly:
<Condition= "' $ (Configuration) |$ (Platform) ' = = ' release| AnyCPU ' "> <AppConfig>App.Release.config</ AppConfig > </ PropertyGroup >
Use context variables to modify to a more general configuration:
< PropertyGroup > < AppConfig > app.$ (Configuration). config</AppConfig></PropertyGroup >