Question

I have gone through every question I have found on StackOverflow and various Google links and not finding this.

We have 3 different servers that require one of the last 3 versions to be deployed to it. This is how I have been handling it on a local build level:

<PostBuildEvent>
  start xcopy /Y /Q "$(TargetDir)EncompassSDKDlls\$(ConfigurationName)\*.*" "$(TargetDir)"
</PostBuildEvent>

And that works great. However, when it tries to do a deploy, it runs it before that. I did try doing some things like: MSDeploy Extra Files but that does not seem to copy the files on the deploy, just the original files that were in the bin directory.

Here was what I tried last:

<PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
        CustomCollectFiles;
        $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
        CustomCollectFiles;
        $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
    <ItemGroup>
        <_CustomFiles Include="Dlls\$(ConfigurationName)\*" />

        <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
            <DestinationRelativePath>(Filename)%(Extension)</DestinationRelativePath>
        </FilesForPackagingFromProject>
    </ItemGroup>
</Target>
<PropertyGroup>
Was it helpful?

Solution 2

Got it to work. The copy did need to be in the post build event, however the FilesForPackagingProject did not have all of the proper settings to recognize the new files. I wanted to post this encase it helps out anyone in the future:

<ItemGroup>
  <_CustomFiles Include="EncompassSDKDlls\$(ConfigurationName)\*" />
  <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
    <DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
  </FilesForPackagingFromProject>
</ItemGroup>

OTHER TIPS

I think that you may be able to get something working by using the %build.number% parameter from TeamCity in your build step.

You mentioned that you need 3 different servers that require one of the last 3 versions deployed to it.

We have used the %build.number% as a parameter to our packaging step, which will produce a deloyment .zip file that has the build number baked into it.

Consider a packaging build step as follows:

Build Step:
Runner type: MSBuild
Step Name: Package
Build file path: <path to ASP.NET project file >.csproj
Command line parameters:
/T:Package 
/P:configuration =BUILD 
/P:DeployServiceUrl=http://build.server:8091 
/p:DeployIisAppPath="IIS_App_Name";PackageLocation ="c:\Packages\%build.number%\Iis_App_Name_%build.number%.zip" 
/p:_PackageTempDir=c:\Packages\Temp

The PackageLocation parameter includes the build number - so your output from builds 100 - 102 would be similar to the following:

c:\Packages\100\Iis_App_Name_100.zip
c:\Packages\101\Iis_App_Name_101.zip
c:\Packages\102\Iis_App_Name_102.zip

You can then use a powershell script that takes the build.number as a parameter, calculates the last three builds, and deploys them to whatever server you need.

As an example the following TeamCity build step will deploy the latest version :

Build Step: 
Runner type: MSBuild
Run : Custom Script
c:\Packages\100\Iis_App_Name_%build.number%.deploy.cmd /Y

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top