Share via


/appconfig (C# Compiler Options)

The /appconfig compiler option enables a C# application to specify the location of an assembly's application configuration (app.config) file to the common language runtime (CLR) at assembly binding time.

/appconfig:file

Arguments

  • file
    Required. The application configuration file that contains assembly binding settings.

Remarks

One use of /appconfig is advanced scenarios in which an assembly has to reference both the .NET Framework version and the .NET Framework for Silverlight version of a particular reference assembly at the same time. For example, a XAML designer written in Windows Presentation Foundation (WPF) might have to reference both the WPF Desktop, for the designer's user interface, and the subset of WPF that is included with Silverlight. The same designer assembly has to access both assemblies. By default, the separate references cause a compiler error, because assembly binding sees the two assemblies as equivalent.

The /appconfig compiler option enables you to specify the location of an app.config file that disables the default behavior by using a <supportPortability> tag, as shown in the following example.

<supportPortability PKT="7cec85d7bea7798e" enable="false"/>

The compiler passes the location of the file to the CLR's assembly-binding logic.

Note

If you are using the Microsoft Build Engine (MSBuild) to build your application, you can set the /appconfig compiler option by adding a property tag to the .csproj file. To use the app.config file that is already set in the project, add property tag <UseAppConfigForCompiler> to the .csproj file and set its value to true. To specify a different app.config file, add property tag <AppConfigForCompiler> and set its value to the location of the file.

Example

The following example shows an app.config file that enables an application to have references to both the .NET Framework implementation and the .NET Framework for Silverlight implementation of any .NET Framework assembly that exists in both implementations. The /appconfig compiler option specifies the location of this app.config file.

<configuration>
      <runtime>
      <assemblyBinding>
            <supportPortability PKT="7cec85d7bea7798e" enable="false"/>
            <supportPortability PKT="31bf3856ad364e35" enable="false"/>
      </assemblyBinding>
      </runtime>
</configuration>

See Also

Reference

<supportPortability> Element

C# Compiler Options Listed Alphabetically

Concepts

.NET Framework Assembly Unification Overview