通过msdeploy / F #Fake脚本包含不在项目中部署的文件

时间:2016-12-13 04:25:36

标签: f# msbuild msdeploy f#-fake

所以我有以下假脚本......

// 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"

我在csproj文件中创建了一些目标,包括生成的/ docs doxygen文档文件夹。这在最初使用我的旧msdeploy脚本时起作用,该脚本是一个msdeploy文件夹同步命令。他们在这里......

  <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>

如何确保Fake脚本执行相同的操作或在csproj文件中执行这些目标?它通过传递您要用于部署项目中的azure发布配置文件的名称来运行。

1 个答案:

答案 0 :(得分:1)

所以在这种情况下,因为我正在部署到azure,我能够将目标和属性组移动到发布配置文件,而不是直接将它们放在项目文件中。所以我在发布资料中结束了以下内容。

<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>

我们将发布配置文件导入到项目中,以便假脚本只接受发布配置文件的名称和发布密码,然后我尝试包含的doxygen文档以及在构建前/事件后创建的doxygen文档是自动包含。我已将此添加到我们的dev / qa发布配置文件中,但未添加到我们的生产发布配置文件中,因为我们不希望将此部署为prod。但在我们的dev / qa环境中自动部署并可供任何人访问是很好的。我在项目中包含了“docs”文件夹。不确定这是否会对其工作方式产生任何影响。

我遵循了本教程...... https://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files。我想这是本教程的扩展...... http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx