0
votes

I'm using TFS as a build server to use MsBuild for building and packaging a solution into a web deploy-package.

MSBuild Arguments: /p:CreatePackageOnPublish=true /p:DeployOnBuild=true /p:DeployTarget=Package

Now I want to copy a couple of files into the source-files before building the package, so they will end up in the App_Data-directory when deployed to IIS. I was thinking of doing it as part of the TFS-build, and have created an InvokeProcess-action which calls xcopy and copies the files into the SourcesDirectory, however they don't appear in the built zip-package.

Into what directory should I copy the files, and where in the build-process? Are there a better way to do this? I was thinking of a Post Build-event in the project-file, however I only want this to be run by specific TFS-build, and not for all builds.

1

1 Answers

3
votes

I deploy specific js versionned files with this hook in my project file :

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

If i remember, this doesn't work for a tfs build because CollectFilesFromContent is not executed in this process, so i have copied the files in a post build event:

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