【问题标题】:Copying files into the source code before building a deploy package with MsBuild on TFS在 TFS 上使用 MsBuild 构建部署包之前将文件复制到源代码中
【发布时间】:2016-02-29 11:40:51
【问题描述】:

我使用 TFS 作为构建服务器,以使用 MsBuild 构建解决方案并将其打包到 Web 部署包中。

MSBuild 参数:/p:CreatePackageOnPublish=true /p:DeployOnBuild=true /p:DeployTarget=Package

现在我想在构建包之前将几个文件复制到源文件中,这样当它们部署到 IIS 时,它们最终会位于 App_Data 目录中。我正在考虑将其作为 TFS 构建的一部分,并创建了一个调用 xcopy 并将文件复制到 SourcesDirectory 的 InvokeProcess-action,但是它们不会出现在构建的 zip 包中。

我应该将文件复制到哪个目录,以及在构建过程中的什么位置? 有没有更好的方法来做到这一点?我正在考虑项目文件中的构建后事件,但是我只希望它由特定的 TFS 构建运行,而不是针对所有构建。

【问题讨论】:

    标签: visual-studio visual-studio-2012 tfs msbuild web-deployment


    【解决方案1】:

    我在我的项目文件中使用这个钩子部署特定的 js 版本控制文件:

    <!--Hook to deploy add files -->
    <PropertyGroup>
        <CollectFilesFromContentDependsOn>
            AddFilesToDeploy;
            $(CollectFilesFromContentDependsOn);
        </CollectFilesFromContentDependsOn>
    </PropertyGroup>
    <!--Add files to deploy -->
    <Target Name="AddFilesToDeploy">
        <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
            <Output TaskParameter="Assemblies" ItemName="CurrentAssembly" />
        </GetAssemblyIdentity>
        <ItemGroup>
            <JsFile Include="script\myApp.min-%(CurrentAssembly.Version).js" />
            <FilesForPackagingFromProject Include="%(JsFile.Identity)">
                <DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
            </FilesForPackagingFromProject>
        </ItemGroup>
    </Target>
    

    如果我记得,这对于 tfs 构建不起作用,因为在此过程中未执行 CollectFilesFromContent,因此我在构建后事件中复制了文件:

    if not '$(TeamFoundationServerUrl)' == '' (
        xcopy "$(ProjectDir)script\myApp.min-@(VersionNumber).js" "$(OutDir)_PublishedWebsites\$(MSBuildProjectName)\script"
    )
    

    【讨论】:

    • 谢谢,我会调查的!
    • Post build 事件对我有用,但是我需要文件以 inside _PublishedWebsites\xxx_Package 中的 package-zip-file 结束。所以我的问题是,我可以在创建 zip 文件之前将文件复制到某个地方,这样它将包含复制的文件吗?干杯!
    • 你需要找到 TFS 用来创建包的进程,并像在我的示例中使用 CollectFilesFromContent 一样挂钩它
    • CopyAllFilesToSingleFolderForPackage 好像你在找
    猜你喜欢
    • 2014-09-20
    • 2011-03-18
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 2013-07-15
    • 2014-03-27
    • 2016-09-17
    • 1970-01-01
    相关资源
    最近更新 更多