Search code examples
c#postsharp

Why is postsharp causing a web project to fail on publish?


In version 4.2.27 of postsharp publishing a web project works correct.

When the postsharp nuget package is upgraded to > 4.2.28 the publish fails. It fails when trying to run TransformWebConfigCore in Microsoft.Web.Publishing.targets. The error

Microsoft.Web.Publishing.targets(1483,5): Error : Could not open Source file: Could not find file '[Project Location]\Web.config;web.config'.


Solution

  • PostSharp 4.2.28 adds Web.config to Content MSBuild ItemGroup automatically. It is the reason why you see web.config twice in the error message:

    Microsoft.Web.Publishing.targets(1483,5): Error : Could not open Source file: Could not find file '[Project Location]\Web.config;web.config'.

    If your csproj contains this element:

    <Content Include="Web.config" />
    

    Change Content to None:

    <None Include="Web.config" />
    

    Make sure that the web.config file is included after publishing your web project.