So, I’m finally really needing to do something with Web.config that isn’t supported by NuGet’s Web.config.transform system.
And after spending 2 hours searching the docs, I realized that there’s no word on whether Install.ps1 happens before or after Web.config.transform gets applied.
I used to define a Web.config.transform file like this:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection"/>
</configSections>
</configuration>
Here’s the new one – the requirePermission="false" attribute is required to support Medium Trust.
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false"/>
</configSections>
</configuration>
If I release a new Web.config.transform version, it will crash their ASP.NET project since there will be two section elements:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection" />
<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false"/>
</configSections>
</configuration>
If Install.ps1 happens before Web.config.transform, I can just delete all matches to configuration/configSections/section[@name='resizer']. If it happens after, then I need to select one of the duplicates to remove.
This is a pretty easy problem to solve, but hasn’t yet been answered on an internet forum, and by posting it I’m hoping to make the next Nuggetter’s life easier.
I just read through NuGet code and install.ps1 happens after Web.config.transform.
In NuGet’s code below, Web.config.transform is called in the ExtractPackageFilesToProject while installs.ps1 is called in the last event OnPackagageReferenceAdded :