Search code examples
f#msbuildmsdeployf#-fake

Include Files to be deployed not in project through msdeploy / F# Fake script


So I have the following Fake script ...

// include Fake lib
#r @"packages\FAKE.4.29.2\tools\FakeLib.dll"
open Fake

RestorePackages()

// define directories
let binDir = "./ProjFileFolder/bin/"
let objDir = "./ProjFileFolder/obj/Debug/"

let buildConf = getBuildParamOrDefault "conf" "Debug"
let buildNumber = getBuildParamOrDefault "bn" "0"
let buildVersion = "1.0.0." + buildNumber

let publishProfile = getBuildParamOrDefault "pubprofile" ""
let publishPassword = getBuildParamOrDefault "pubpwd" ""

let setParamsWeb = [
       "DebugSymbols", "True"
       "Configuration", buildConf
       "Platform", "Any CPU"
       "PublishProfile", publishProfile
       "DeployOnBuild", "true"
       "Password", publishPassword
       "AllowUntrustedCertificate", "true"
   ]

// Targets
Target "Clean" (fun _ ->
    CleanDirs [binDir; objDir]
)

Target "Compile" (fun _ ->
    !! @"**\*.csproj"
      |> MSBuild binDir "Build" setParamsWeb
      |> Log "AppBuild-Output: "
)

// Dependencies
"Clean"
    ==> "Compile"

// start build
RunTargetOrDefault "Compile"

I had some targets that I had created in the csproj file to include a generated /docs doxygen documentation folder. This worked when initially using my old msdeploy script, which was an msdeploy folder sync command. Here they are ...

  <Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include=".\docs\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>docs\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>

  <Choose>
    <When Condition="'$(Configuration)' == 'Debug'">
      <PropertyGroup>
        <CopyAllFilesToSingleFolderForPackageDependsOn>
          CustomCollectFiles;
          $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForPackageDependsOn>
      </PropertyGroup>
    </When>
    <When Condition="'$(Configuration)' == 'QA'">
      <PropertyGroup>
        <CopyAllFilesToSingleFolderForPackageDependsOn>
          CustomCollectFiles;
          $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForPackageDependsOn>
      </PropertyGroup>
    </When>
  </Choose>

How do I ensure that the Fake script does the same thing or that it executes those targets in the csproj file? It runs by passing the name of the azure publish profile in that you want to use to deploy which is in the project.


Solution

  • So in this case because I'm deploying to azure I was able to move the targets and property group to the publish profile instead of having them in the project file directly. So I ended up with the following in our publish profile.

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <WebPublishMethod>MSDeploy</WebPublishMethod>
        <ADUsesOwinOrOpenIdConnect>False</ADUsesOwinOrOpenIdConnect>
        <PublishProvider>AzureWebSite</PublishProvider>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish>stuff</SiteUrlToLaunchAfterPublish>
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>False</ExcludeApp_Data>
        <MSDeployServiceURL>stuff</MSDeployServiceURL>
        <DeployIisAppPath>more stuff</DeployIisAppPath>
        <RemoteSitePhysicalPath />
        <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
        <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
        <EnableMSDeployBackup>True</EnableMSDeployBackup>
        <UserName>more stuff</UserName>
        <_SavePWD>True</_SavePWD>
        <_DestinationType>AzureWebSite</_DestinationType>
      </PropertyGroup>
      <Target Name="CustomCollectFiles" BeforeTargets="Compile">
        <ItemGroup>
          <_CustomFiles Include=".\docs\**\*" />
          <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
            <DestinationRelativePath>docs\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
          </FilesForPackagingFromProject>
        </ItemGroup>
      </Target>
      <PropertyGroup>
        <CopyAllFilesToSingleFolderForPackageDependsOn>
          CustomCollectFiles;
          $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForPackageDependsOn>
      </PropertyGroup>
      <PropertyGroup>
        <CopyAllFilesToSingleFolderForMsdeployDependsOn>
          CustomCollectFiles;
          $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForMsdeployDependsOn>
      </PropertyGroup>
    </Project>
    

    We import the publish profiles into the project so that the fake script just accepts the name of the publish profile and the publish password and then the doxygen documentation which I am trying to include and which is created upon pre/post build event is included automatically. I have added this to our dev / qa publish profiles but not to our production publish profile because we don't want this deployed to prod. But it is nice to have automatically deployed and available in our dev / qa environments for anyone to access. I have included the "docs" folder in the project. Not sure if that will have any impact upon how it works.

    I followed this tutorial ... https://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files . Which I suppose is an extension of this tutorial ... http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx