|
| 1 | +<!-- |
| 2 | + ==================================================================================================== |
| 3 | +
|
| 4 | + GenerateBindingRedirects Behaviors |
| 5 | + |
| 6 | + Traditionally (Microsoft.Common.CurrentVersion.targets) only Performs BindingRedirect calculations when |
| 7 | + Project type is deemed to "need" redirects -> when OutputType == 'exe' or OutputType == 'winexe' (Microsoft.Common.CurrentVersion.targets) |
| 8 | + AND |
| 9 | + Not an "old" project, aka either |
| 10 | + An SDK project type that incorporates Microsoft.NET.Sdk (Microsoft.NET.Sdk.BeforeCommon.targets) |
| 11 | + OR |
| 12 | + A newer Full Framework project TargetFrameworkIdentifier == '.NETFramework' and '$(TargetFrameworkVersion.TrimStart(vV))' >= '4.7.2' (Microsoft.Common.CurrentVersion.targets) |
| 13 | + Additionally it chooses the filename of the config file to be updated as what exe projects want... |
| 14 | + $(IntermediateOutputPath)$(TargetFileName).config -> the config file named after the assembly and in the IntermediateOutputPath |
| 15 | + |
| 16 | + https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/34 |
| 17 | + This SDK Project Type will override these settings so that we can facilitate developers working with BindingRedirects in the web.config |
| 18 | + Enable the Build Process to calculate Binding Redirects |
| 19 | + GenerateBindingRedirectsOutputType(true - even though this project is not an .exe or .winexe) |
| 20 | + AutoGenerateBindingRedirects (true - set explictly even though should be set by Microsoft.NET.Sdk.BeforeCommon.targets) |
| 21 | + Take an action |
| 22 | + OverwriteAppConfigWithBindingRedirects -> this is the SystemWeb Sdk Legacy property |
| 23 | + GeneratedBindingRedirectsAction (Overwrite) -> this will conditionally change wich config file is written to |
| 24 | + ==================================================================================================== |
| 25 | + --> |
| 26 | + |
| 27 | +<Project> |
| 28 | + |
| 29 | + <PropertyGroup Label="Change the default BindingRedirects behavior for projects of this SDK type"> |
| 30 | + <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> |
| 31 | + <AutoGenerateBindingRedirects Condition=" '$(AutoGenerateBindingRedirects)' == '' ">true</AutoGenerateBindingRedirects> |
| 32 | + </PropertyGroup> |
| 33 | + |
| 34 | + <PropertyGroup Label="Set the desire default behavior of what to do with SuggestedBindingRedirects if not yet set" |
| 35 | + Condition=" '$(GeneratedBindingRedirectsAction)' == ''"> |
| 36 | + <GeneratedBindingRedirectsAction>None</GeneratedBindingRedirectsAction> |
| 37 | + <GeneratedBindingRedirectsAction Condition=" '$(OverwriteAppConfigWithBindingRedirects)' != 'true' ">Preview</GeneratedBindingRedirectsAction> |
| 38 | + <GeneratedBindingRedirectsAction Condition=" '$(OverwriteAppConfigWithBindingRedirects)' == 'true' ">Overwrite</GeneratedBindingRedirectsAction> |
| 39 | + </PropertyGroup> |
| 40 | + |
| 41 | + |
| 42 | + <!-- |
| 43 | + ==================================================================================================== |
| 44 | +
|
| 45 | + SystemWebProject_ChooseConfigFileForGenerateBindingRedirects |
| 46 | + |
| 47 | + This target should executes between |
| 48 | + ResolveAssmblyReferences (where the "@(SuggestedBindingRedirects)" itemgroup is populated... based on the logic that resolves assemblies being referenced |
| 49 | + and |
| 50 | + GenerateBindingRedirects (where the suggestedBindingRedirects are written to disk into a config file at $(_GenerateBindingRedirectsIntermediateAppConfig) |
| 51 | + |
| 52 | + Then we can choose where the suggestedBindingRedirects are written, if at all (Default Value is Overwrite unless set by project) |
| 53 | + '$(GeneratedBindingRedirectsAction)' == 'Preview' -> Creates new Web.BindingRedirects.config file showing proposed changes |
| 54 | + '$(GeneratedBindingRedirectsAction)' == 'Overwrite' -> Updates the $(AppConfig) aka web.config in the project root |
| 55 | + '$(GeneratedBindingRedirectsAction)' == Something Unknown -> Prints message giving options of what the developer can choose from |
| 56 | + |
| 57 | + In general we want to emit a "warning" whenever we either do, or don't do something to help developers find the property that drives this behavior |
| 58 | + ==================================================================================================== |
| 59 | + --> |
| 60 | + <Target Name="SystemWebProject_ChooseConfigFileForGenerateBindingRedirects" |
| 61 | + BeforeTargets="GenerateBindingRedirects" |
| 62 | + Condition="'$(AutoGenerateBindingRedirects)' == 'true' and '$(GenerateBindingRedirectsOutputType)' == 'true' and @(SuggestedBindingRedirects->Count()) > 0 "> |
| 63 | + |
| 64 | + <PropertyGroup Label="Set the location of the file to which the suggestedBindingRedirects should be written during the GenerateBindingRedirects Target"> |
| 65 | + <_GenerateBindingRedirectsIntermediateAppConfig Condition="'$(GeneratedBindingRedirectsAction)' == 'Preview' " >Web.BindingRedirects.config</_GenerateBindingRedirectsIntermediateAppConfig> |
| 66 | + <_GenerateBindingRedirectsIntermediateAppConfig Condition="'$(GeneratedBindingRedirectsAction)' == 'Overwrite' " >$(AppConfig)</_GenerateBindingRedirectsIntermediateAppConfig> |
| 67 | + </PropertyGroup> |
| 68 | + |
| 69 | + <Warning Condition="'$(GeneratedBindingRedirectsAction)' != 'Preview' and '$(GeneratedBindingRedirectsAction)' != 'Overwrite'" |
| 70 | + Text="Generated Binding Redirects have been applied only to the $(TargetFileName).config. You should incorporate them into the web.config. Consider setting <GeneratedBindingRedirectsAction>Preview</GeneratedBindingRedirectsAction> to create a file containing the proposals. Consider setting <GeneratedBindingRedirectsAction>Overwrite</GeneratedBindingRedirectsAction> to automatically update web.config with proposals." /> |
| 71 | + |
| 72 | + <Warning Condition="'$(GeneratedBindingRedirectsAction)' == 'Preview'" |
| 73 | + Text="Generated Binding Redirects have been applied only to the Web.BindingRedirects.config. You should incorporate them into the web.config. Consider setting <GeneratedBindingRedirectsAction>Overwrite</GeneratedBindingRedirectsAction> to automatically update web.config with proposals." /> |
| 74 | + |
| 75 | + <Warning Condition="'$(GeneratedBindingRedirectsAction)' == 'Overwrite'" |
| 76 | + Text="Generated Binding Redirects have been applied automatically to the web.config. This warning will disappear on the next build." /> |
| 77 | + |
| 78 | + </Target> |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +</Project> |
0 commit comments