Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content items brought in by EnableWebFormsDefaultItems include (published) output under bin and obj #25

Closed
CZEMacLeod opened this issue Nov 17, 2021 · 8 comments

Comments

@CZEMacLeod
Copy link
Owner

@CZEMacLeod Thanks for the great work on this project. I updated to this version and noticed an issue after performing a publish.

In my project I end up with "bin\Release\Publish" as the output folder, however if turn on EnableWebFormsDefaultItems, once I publish it see's that published folder as content. Then each publish adds more content upon itself and eventually errors.

I have worked around this in some of my other globs by adding Exclude="$(DefaultItemExcludes)".

I recommend changing from:

<Content Include="**\*.asax" />
<Content Include="**\*.ascx" />
<Content Include="**\*.ashx" />
<Content Include="**\*.asmx" />
<Content Include="**\*.aspx" />
<Content Include="**\*.master" />

to

<Content Include="**\*.asax" Exclude="$(DefaultItemExcludes)" />
<Content Include="**\*.ascx" Exclude="$(DefaultItemExcludes)" />
<Content Include="**\*.ashx" Exclude="$(DefaultItemExcludes)" />
<Content Include="**\*.asmx" Exclude="$(DefaultItemExcludes)" />
<Content Include="**\*.aspx" Exclude="$(DefaultItemExcludes)" />
<Content Include="**\*.master" Exclude="$(DefaultItemExcludes)" />

Originally posted by @mcnallys in #24 (comment)

@CZEMacLeod
Copy link
Owner Author

CZEMacLeod commented Nov 17, 2021

@mcnallys The props file actually adds all the item types to DefaultItemExcludes so using that to exclude won't work.
However, we can setup excludes for the Content entries

  <!-- Exclude WebForms items from default items -->
  <PropertyGroup Condition="'$(EnableWebFormsDefaultItems)'=='true'">
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.asax;*.asax</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.ascx;*.ascx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.ashx;*.ashx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.asmx;*.asmx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.aspx;*.aspx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.master;*.master</DefaultItemExcludes>
    <DefaultWebFormsItemExcludes>$(BaseOutputPath)\**;$(BaseIntermediateOutputPath)\**</DefaultWebFormsItemExcludes>
  </PropertyGroup>

  <!-- Include WebForms items as content -->
  <ItemGroup Condition="'$(EnableWebFormsDefaultItems)'=='true'">
    <Content Include="**\*.asax" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.ascx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.ashx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.asmx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.aspx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.master" Exclude="$(DefaultWebFormsItemExcludes)" />
  </ItemGroup>

If you try this (but change EnableWebFormsDefaultItems to EnableWebFormsDefaultItems2) and it resolves the issue for you, I can make the update and publish.

@mcnallys
Copy link

I'm trying to follow but not quite understanding, am I changing these files locally in my project or yours?

@CZEMacLeod
Copy link
Owner Author

@mcnallys Add the following to your project file and change <EnableWebFormsDefaultItems>true</EnableWebFormsDefaultItems> to <EnableWebFormsDefaultItems2>true</EnableWebFormsDefaultItems2>

  <!-- Exclude WebForms items from default items -->
  <PropertyGroup Condition="'$(EnableWebFormsDefaultItems2)'=='true'">
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.asax;*.asax</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.ascx;*.ascx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.ashx;*.ashx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.asmx;*.asmx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.aspx;*.aspx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.master;*.master</DefaultItemExcludes>
    <DefaultWebFormsItemExcludes>$(BaseOutputPath)\**;$(BaseIntermediateOutputPath)\**</DefaultWebFormsItemExcludes>
  </PropertyGroup>

  <!-- Include WebForms items as content -->
  <ItemGroup Condition="'$(EnableWebFormsDefaultItems2)'=='true'">
    <Content Include="**\*.asax" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.ascx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.ashx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.asmx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.aspx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.master" Exclude="$(DefaultWebFormsItemExcludes)" />
  </ItemGroup>

This will allow you to test the update - if it works correctly for you, then I will make the changes to MSBuild.SDK.SystemWeb.DefaultItems.props.
Once updated you can revert to <EnableWebFormsDefaultItems>true</EnableWebFormsDefaultItems> and remove the temporaryPropertyGroup and ItemGroup.

@mcnallys
Copy link

mcnallys commented Nov 18, 2021

This almost worked but my baseoutputpath and baseintermediateoutputpath already had a trailing slash.

<!-- Exclude WebForms items from default items -->
  <PropertyGroup Condition="'$(EnableWebFormsDefaultItems2)'=='true'">
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.asax;*.asax</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.ascx;*.ascx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.ashx;*.ashx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.asmx;*.asmx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.aspx;*.aspx</DefaultItemExcludes>
    <DefaultItemExcludes>$(DefaultItemExcludes);**\*.master;*.master</DefaultItemExcludes>
    <DefaultWebFormsItemExcludes>$(BaseOutputPath)**;$(BaseIntermediateOutputPath)**</DefaultWebFormsItemExcludes>
  </PropertyGroup>

    <!-- Include WebForms items as content -->
  <ItemGroup Condition="'$(EnableWebFormsDefaultItems2)'=='true'">
    <Content Include="**\*.asax" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.ascx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.ashx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.asmx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.aspx" Exclude="$(DefaultWebFormsItemExcludes)" />
    <Content Include="**\*.master" Exclude="$(DefaultWebFormsItemExcludes)" />
  </ItemGroup>

Notice $(BaseOutputPath)** instead of $(BaseOutputPath)\**
and
$(BaseIntermediateOutputPath)** instead of $(BaseIntermediateOutputPath)\**

That fixed it locally and I will report back on the results of our build system.

@mcnallys
Copy link

Everything looked good in the build.

@CZEMacLeod
Copy link
Owner Author

@mcnallys This logic should be implemented with V4.0.58 - Let me know if you have any issues.

@mcnallys
Copy link

mcnallys commented Nov 18, 2021

Well I was so hopeful, it's still including the obj folder.

image

If I add this line to my project it works as expected.

<DefaultWebFormsItemExcludes>$(DefaultWebFormsItemExcludes);$([MSBuild]::EnsureTrailingSlash($(BaseIntermediateOutputPath)))**</DefaultWebFormsItemExcludes>

I wonder if BaseIntermediateOutputPath is not populated at the time it's being evaluated.

@CZEMacLeod
Copy link
Owner Author

@mcnallys I think I have found the issue - the PropertyGroup defining the DefaultWebFormsItemExcludes was predicated on EnableWebFormsDefaultItems but was in the .props file meaning it was imported and evaluated before the project file.
This meant that it wasn't being triggered, so when the ItemGroups were evaluated, nothing happened.
When you inlined it in the project it would have been after your define of <EnableWebFormsDefaultItems>true</EnableWebFormsDefaultItems> so it worked.
I have moved the property group to a targets file so it gets checked after the project file is imported and the flag detected.
The ItemGroup is evaluated in a later phase so it works as expected in the props file and allows you to override it in the project file as expected.
This means that V4.0.63 should now work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants