none
Visual Studio 2017 Publish + FileSystem + Create Empty Folder RRS feed

  • Question

  • Hi,

    Hope this is right group. We publish ASP.NET web application using 'Publish'. We chose FileSystem option. This do not copy 'Empty folder'. We need this folder to be created. 2 options I am seeing.

          1. Manually create folder on server

          2. Create dummy file in a folder and publish

    Both works, but we do not want to do it. When I searched, I see below code for MSBuild option by editing .pubxml fie

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    This file is used by the publish/package process of your Web project. You can customize the behavior of this process
    by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
    -->
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <AfterAddIisSettingAndFileContentsToSourceManifest>CreateEmptyFolders</AfterAddIisSettingAndFileContentsToSourceManifest>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>True</ExcludeApp_Data>
        <publishUrl>\\clientportal-dev\CPDev$</publishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
      </PropertyGroup>
      <Target Name="CreateEmptyFolders">
        <Message Text="Adding empty folder to hold Files" />
        <MakeDir Directories="$(_MSDeployDirPath_FullPath)\CustomReports"/>
      </Target>
    </Project>

    After adding this, I rebuilt project in release mode and published. Nothing is working.

    Please suggest if anyone know.

    Thanks,

    Thursday, January 23, 2020 7:46 PM

All replies

  • Hi Spunny,

    Welcome to MSDN forum.

    For you requirement, you need to modify your <target> section. Please refer these steps:

    #1, modify your pubxml file like this:

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>True</ExcludeApp_Data>
        <publishUrl>D:\test</publishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
      </PropertyGroup>
      <Target Name="CustomCollectFiles" AfterTargets="Build">
        <MakeDir Directories="$(PublishDirectory)$(OutputDirectoryTemp)" />
        <Message Text="$(PublishDirectory)$(OutputDirectoryTemp)">
        </Message>
      </Target>
      <PropertyGroup>
        <OutputDirectoryTemp>\Temp\</OutputDirectoryTemp>
      </PropertyGroup>
      <PropertyGroup>
        <PublishDirectory>D:\Publish</PublishDirectory>
      </PropertyGroup>
    </Project>

    #2, type the command in developer command prompt for VS 2017

    msbuild D:\WebApplication1\WebApplication1\WebApplication1.csproj /p:DeployonBuild=true /p:PublishProfile=xxx.pubxml
    After that, you will see the "D:\Publish\Temp"folder will be created.

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Friday, January 24, 2020 8:31 AM
  • Thank you Dylan. It works if I use msbuild at command prompt. What I needed is above to work, if I click on 'Publish' button in Build -> Publish Project1 -> Publish tab -> Publish button in Visual Studio.

    For above code, I tried clicking on Publish button. It didn't work. Please suggest.

    Thank You,

    Spunny

    Friday, January 24, 2020 3:35 PM
  • Hi Spunny,

    Sorry for this delay in reply.

    I have modified the code you shared, and test it in VS IDE, it could work. Maybe you could have a tried the code from my previous reply. 

    If it still failed in VS IDE, I'm afraid that there are some problems about publish feature in your VS. Please try to repair your VS then publish it again.

    Any feedback will be expected.

    Best Regards,

    Dylan 


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, January 27, 2020 6:20 AM