-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMSBuild.SDK.SystemWeb.Common.BindingRedirects.targets
More file actions
135 lines (111 loc) · 9.12 KB
/
MSBuild.SDK.SystemWeb.Common.BindingRedirects.targets
File metadata and controls
135 lines (111 loc) · 9.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!--
====================================================================================================
GenerateBindingRedirects Behaviors
Traditionally (Microsoft.Common.CurrentVersion.targets) only Performs BindingRedirect calculations when
Project type is deemed to "need" redirects -> when OutputType == 'exe' or OutputType == 'winexe' (Microsoft.Common.CurrentVersion.targets)
AND
Not an "old" project, aka either
An SDK project type that incorporates Microsoft.NET.Sdk (Microsoft.NET.Sdk.BeforeCommon.targets)
OR
A newer Full Framework project TargetFrameworkIdentifier == '.NETFramework' and '$(TargetFrameworkVersion.TrimStart(vV))' >= '4.7.2' (Microsoft.Common.CurrentVersion.targets)
Additionally it chooses the filename of the config file to be updated as what exe projects want...
$(IntermediateOutputPath)$(TargetFileName).config -> the config file named after the assembly and in the IntermediateOutputPath
https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/34
This SDK Project Type will override these settings so that we can facilitate developers working with BindingRedirects in the web.config
Enable the Build Process to calculate Binding Redirects
GenerateBindingRedirectsOutputType(true - even though this project is not an .exe or .winexe)
AutoGenerateBindingRedirects (true - set explictly even though should be set by Microsoft.NET.Sdk.BeforeCommon.targets)
Take an action
OverwriteAppConfigWithBindingRedirects -> this is the SystemWeb Sdk Legacy property
GeneratedBindingRedirectsAction (Overwrite) -> this will conditionally change wich config file is written to
https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/58
This file is now common to both the MSBuild.SDK.SystemWeb and MSBuild.SDK.SystemWeb.RazorLibrary SDKs
As MVC Views folders often have their own copy of web.config, we need to ensure we add any binding redirects to those files too.
These are picked up by default into the RazorAppConfigFiles item group
====================================================================================================
-->
<Project>
<ItemGroup Condition="'$(BuildingInsideVisualStudio)'=='true'">
<AvailableItemName Include="RazorAppConfigFiles" />
</ItemGroup>
<ItemDefinitionGroup>
<RazorAppConfigFiles>
<Preview>%(RootDir)%(Directory)%(FileName).BindingRedirects%(Extension)</Preview>
</RazorAppConfigFiles>
</ItemDefinitionGroup>
<ItemGroup Condition="$(EnableDefaultItems)">
<RazorAppConfigFiles Include="Views/web.config" Condition="EXISTS('Views/web.config')" />
<RazorAppConfigFiles Include="Areas/**/web.config" />
</ItemGroup>
<PropertyGroup Label="Change the default BindingRedirects behavior for projects of this SDK type">
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AutoGenerateBindingRedirects Condition=" '$(AutoGenerateBindingRedirects)' == '' ">true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Label="Set the desired default behavior of what to do with SuggestedBindingRedirects if not yet set"
Condition=" '$(GeneratedBindingRedirectsAction)' == ''">
<GeneratedBindingRedirectsAction>None</GeneratedBindingRedirectsAction>
<GeneratedBindingRedirectsAction Condition=" '$(OverwriteAppConfigWithBindingRedirects)' != 'true' ">Preview</GeneratedBindingRedirectsAction>
<GeneratedBindingRedirectsAction Condition=" '$(OverwriteAppConfigWithBindingRedirects)' == 'true' ">Overwrite</GeneratedBindingRedirectsAction>
</PropertyGroup>
<!--
====================================================================================================
SystemWebProject_ChooseConfigFileForGenerateBindingRedirects
This target should executes between
ResolveAssmblyReferences (where the "@(SuggestedBindingRedirects)" itemgroup is populated... based on the logic that resolves assemblies being referenced
and
GenerateBindingRedirects (where the suggestedBindingRedirects are written to disk into a config file at $(_GenerateBindingRedirectsIntermediateAppConfig)
Then we can choose where the suggestedBindingRedirects are written, if at all (Default Value is Overwrite unless set by project)
'$(GeneratedBindingRedirectsAction)' == 'Preview' -> Creates new Web.BindingRedirects.config file showing proposed changes
'$(GeneratedBindingRedirectsAction)' == 'Overwrite' -> Updates the $(AppConfig) aka web.config in the project root
'$(GeneratedBindingRedirectsAction)' == Something Unknown -> Prints message giving options of what the developer can choose from
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
====================================================================================================
-->
<Target Name="SystemWebProject_ChooseConfigFileForGenerateBindingRedirects"
BeforeTargets="GenerateBindingRedirects"
Condition="'$(AutoGenerateBindingRedirects)' == 'true' and
'$(GenerateBindingRedirectsOutputType)' == 'true' and
@(SuggestedBindingRedirects->Count()) > 0 ">
<PropertyGroup Label="Set the location of the file to which the suggestedBindingRedirects should be written during the GenerateBindingRedirects Target">
<_GenerateBindingRedirectsIntermediateAppConfig Condition="'$(GeneratedBindingRedirectsAction)' == 'Preview' " >Web.BindingRedirects.config</_GenerateBindingRedirectsIntermediateAppConfig>
<_GenerateBindingRedirectsIntermediateAppConfig Condition="'$(GeneratedBindingRedirectsAction)' == 'Overwrite' " >$(AppConfig)</_GenerateBindingRedirectsIntermediateAppConfig>
</PropertyGroup>
<Warning Condition="'$(GeneratedBindingRedirectsAction)' != 'Preview' and '$(GeneratedBindingRedirectsAction)' != 'Overwrite'"
File="$(TargetFileName).config"
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." />
<Warning Condition="'$(GeneratedBindingRedirectsAction)' == 'Preview'"
File="Web.BindingRedirects.config"
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." />
<Warning Condition="'$(GeneratedBindingRedirectsAction)' == 'Overwrite'"
File="Web.config"
Text="Generated Binding Redirects have been applied automatically to the Web.config. This warning will disappear on the next build." />
</Target>
<Target Name="SystemWebProject_RazorAppConfigFilesBindingRedirects"
AfterTargets="GenerateBindingRedirects"
Condition="'$(AutoGenerateBindingRedirects)' == 'true' and
'$(GenerateBindingRedirectsOutputType)' == 'true' and
@(RazorAppConfigFiles->Count()) > 0 and
'$(GeneratedBindingRedirectsAction)' != 'None' and
@(SuggestedBindingRedirects->Count()) > 0 ">
<GenerateBindingRedirects SuggestedRedirects="@(SuggestedBindingRedirects)"
AppConfigFile="%(RazorAppConfigFiles.Identity)"
OutputAppConfigFile="%(RazorAppConfigFiles.Preview)"
Condition="'$(GeneratedBindingRedirectsAction)' == 'Preview'" />
<Warning Condition="'$(GeneratedBindingRedirectsAction)' == 'Preview'"
File="%(RazorAppConfigFiles.Preview)"
Text="Generated Binding Redirects have been applied only to %(RazorAppConfigFiles.Preview).
You should incorporate them into the %(RazorAppConfigFiles.Identity).
Consider setting <GeneratedBindingRedirectsAction>Overwrite</GeneratedBindingRedirectsAction> to automatically update the file with proposals." />
<GenerateBindingRedirects SuggestedRedirects="@(SuggestedBindingRedirects)"
AppConfigFile="%(RazorAppConfigFiles.Identity)"
OutputAppConfigFile="%(RazorAppConfigFiles.Identity)"
Condition="'$(GeneratedBindingRedirectsAction)' == 'Overwrite'" />
<Warning Condition="'$(GeneratedBindingRedirectsAction)' == 'Overwrite'"
File="%(RazorAppConfigFiles.Identity)"
Text="Generated Binding Redirects have been applied automatically to %(RazorAppConfigFiles.Identity). This warning will disappear on the next build." />
</Target>
</Project>