CZEMacLeod / MSBuild.SDK.SystemWeb

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.
MIT License
151 stars 8 forks source link

.aspx and .asax files don't get published #24

Closed chucker closed 2 years ago

chucker commented 2 years ago

I'm deploying as follows:

msbuild /t:Restore,Rebuild /p:DeployOnBuild=true /p:PublishProfile=Live.pubxml
/p:Password="(my password)" /p:Configuration=Live .\MyProject\MyProject.csproj

This does build a new DLL and upload that and its dependencies to the server. However, it does not replace any aspx files on the server.

I notice VS infers the build action for aspx as None, and I'm not seeing a reason at a glance, in my csproj. Some snippets:

<Project Sdk="MSBuild.SDK.SystemWeb/4.0.49">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <UseIISExpress>true</UseIISExpress>
    <IISExpressSSLPort>44304</IISExpressSSLPort>
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <UseGlobalApplicationHostFile />
    <Use64BitIISExpress />
    <LangVersion>9.0</LangVersion>
    <AssemblyTitle>MyProject</AssemblyTitle>
  </PropertyGroup>
  <ItemGroup>
    [.. a few package references]
  </ItemGroup>
  <ItemGroup>
    [.. a few linked files to add to compilation]
  </ItemGroup>
  <ItemGroup>
    <PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="3.11.0" />
  </ItemGroup>
</Project>

I'm guessing asmx and ascx files would be affected as well.

So I think the default item includes should have:

  <ItemGroup>
    <Content Include="*.asax" />
    <Content Include="*.ascx" />
    <Content Include="*.asmx" />
    <Content Include="*.aspx" />
  </ItemGroup>
CZEMacLeod commented 2 years ago

It has been a while since I did webforms development (I mainly use/maintain MVC and Razor these days). Are there any other types that should be included? I seem to remember master pages (.master?). I believe these should be recursive so they include at any depth of folder, not just the root so probably something like

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

I'll look at adding these as default includes, perhaps behind a flag so that they can be disabled if required.

chucker commented 2 years ago

Good point — .master, too. And yes, it should be recursive (technically, the rules are more complex; e.g. App_Code should not contain markup).

klinki commented 2 years ago

I believe .ashx should be also included

chucker commented 2 years ago

Possibly also resx, axd, config.

CZEMacLeod commented 2 years ago

@chucker .resx and web.config files were already handled. And .axd files do not actually exist - the URLs are just routed to a handler class by IIS.

mcnallys commented 2 years ago

@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)" />
CZEMacLeod commented 2 years ago

@mcnallys I've created a new issue #25 for this problem.