views:

30

answers:

1

Hi,

I'm just about to setup teamcity for the first time on my own. Very nice and simple in most ways I have to say. However, I have one issue that I haven't manage to solve and find any information about.

When I wanna publish my artifacts I want to exclude some file types.

example:

%system.agent.work.dir%\trunk\Source\Projects\Webproject.Web/Controllers => Webproject.Web/Controllers

However, I don't want to copy all the .cs files in the folder. I just need the folder. Is it possible to copy just the folder and not the content, and then copy what ever content I need? Or can I exclude files if I copy a directory?

+1  A: 

You can add a MSBUILD target which prepares the "deployment" package for you. I have the following (may need some changes for your project):

  <Target Name="Publish" DependsOnTargets="Build" Condition="'$(WebProjectOutputDir)'!=''">
    <RemoveDir Directories="$(WebProjectOutputDir)" ContinueOnError="true" />
    <!-- Log tasks -->
    <Message Text="Publishing web application for $(MSBuildProjectName)" />
    <Message Text="WebProjectOutputDir: $(WebProjectOutputDir)" />
    <!-- Create the _PublishedWebsites\app\bin folder -->
    <MakeDir Directories="$(WebProjectOutputDir)\bin" />
    <!-- Copy build outputs to _PublishedWebsites\app\bin folder -->
    <Copy SourceFiles="@(IntermediateAssembly)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Copy SourceFiles="@(AddModules)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Copy SourceFiles="$(IntermediateOutputPath)$(_SGenDllName)" DestinationFolder="$(WebProjectOutputDir)\%(Content.SubFolder)%(Content.RecursiveDir)" SkipUnchangedFiles="true" Condition="'$(_SGenDllCreated)'=='true'" />
    <Copy SourceFiles="$(IntermediateOutputPath)$(TargetName).pdb" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DebugSymbolsProduced)'=='true'" />
    <Copy SourceFiles="@(DocFileItem)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DocumentationFileProduced)'=='true'" />
    <Copy SourceFiles="@(IntermediateSatelliteAssembliesWithTargetPath)" DestinationFiles="@(IntermediateSatelliteAssembliesWithTargetPath->'$(WebProjectOutputDir)\bin\%(Culture)\$(TargetName).resources.dll')" SkipUnchangedFiles="true" />
    <Copy SourceFiles="@(ReferenceComWrappersToCopyLocal); @(ResolvedIsolatedComModules); @(_DeploymentLooseManifestFile); @(NativeReferenceFile)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <!-- copy any referenced assemblies to _PublishedWebsites\app\bin folder -->
    <Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFiles="@(ReferenceCopyLocalPaths->'$(WebProjectOutputDir)\bin\%(DestinationSubDirectory)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
    <!-- Copy content files recursively to _PublishedWebsites\app\ folder -->
    <Copy SourceFiles="@(Content)" DestinationFolder="$(WebProjectOutputDir)\%(Content.RelativeDir)" />
    <!-- Copy items that have been marked to be copied to the bin folder -->
    <Copy SourceFiles="@(_SourceItemsToCopyToOutputDirectory)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Copy SourceFiles="@(_SourceItemsToCopyToOutputDirectoryAlways)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="false" />
  </Target>

So, in the TC build, I use the MSBUILD builder like this:

Targets: Rebuild;Publish

Command line parameters: /p:WebProjectOutputDir="%system.teamcity.build.workingDir%\Website"

You can then use the Website directory as your artifact.

Lucero
Okay, I'm a bit lost when it comes to where I should add this MSBuild Target. I can see what you're doing though and makes sense.
MrW
Preferanle I would like to be able to control it all from the TC ui though, and not have to deal with MSbuild Targets. It's kind of odd that it's not possible to copy just a folder though.
MrW
Well, arguably creating a deployment package is part of the build process. The artifacts are just "collected" from the generated build outputs. Therefore I believe that having everything in your build file is the way to go; it allows you to test and modify the deployment package, and it is part of your source code, so that setting up an identical build in the future is easy to do. Just open your CSPROJ file in a text editor (its a MSBUILD script) and add the target at the very bottom of the file, just before the closing root tag. That should be all you need.
Lucero
Okay, I see your point there! So have to do that then indivually for all the projects that in my solution? Also, completely different question and should be posted as it's own, but versioning of assemblies? is that possible in TC, do you know?
MrW
Well, I use one build configuration per MVC site. But each MVC site needs to get this target inserted, yes (the target is actually a bug-fixed version of the one that VS uses internally when doing a "Publish" using a right-click on the web project in the Solution Explorer). Regarding versioning, I just use the automatic assembly version scheme (something like this: `[assembly: AssemblyVersion("1.0.*")]`) and have the assemblies signed with a strong name key. I use TC build triggers and artifact dependencies to make sure that all dependent projects are rebuilt with the current versions.
Lucero
If you're interested on the fixes on the publish target, they're documented here: http://forums.asp.net/t/1043621.aspx (note that the original target name is `_CopyWebApplication` and not `Publish`).
Lucero