What's the best way to get TFS to output each project to its own directory?

前端 未结 11 1151
我寻月下人不归
我寻月下人不归 2020-11-30 18:58

I\'m putting a large codebase into Team Foundation Server. I would like the build process to create a \"ready to deploy\" build of our projects.

The normal way we\'v

相关标签:
11条回答
  • 2020-11-30 19:22

    Update for TFS 2010 (and upcoming TFS 2012). Jason Stangroome has written a nice blog post outlining how to do this.

    https://blog.stangroome.com/2012/02/03/override-the-tfs-team-build-outdir-property/

    Override the TFS Team Build OutDir property

    Update: with .NET 4.5 there is an easier way.

    A very common complaint from users of Team Foundation Server’s build system is that it changes the folder structure of the project outputs. By default Visual Studio puts all the files in each project’s respective /bin/ or /bin// folder but Team Build just uses a flat folder structure putting all the files in the drop folder root or, again, a // subfolder in the drop folder, with all project outputs mixed together.

    Additionally because Team Build achieves this by setting the OutDir property via the MSBuild.exe command-line combined with MSBuild’s property precedence this value cannot easily be changed from within MSBuild itself and the popular solution is to edit the Build Process Template *.xaml file to use a different property name. But I prefer not to touch the Workflow unless absolutely necessary.

    Instead, I use both the Solution Before Target and the Inline Task features of MSBuild v4 to override the default implementation of the MSBuild Task used to build the individual projects in the solution. In my alternative implementation, I prevent the OutDir property from being passed through and I pass through a property called PreferredOutDir instead which individual projects can use if desired.

    The first part, substituting the OutDir property for the PreferredOutDir property at the solution level is achieved simply by adding a new file to the directory your solution file resides in. This new file should be named following the pattern “before..sln.targets”, eg for a solution file called “Foo.sln” then new file would be “before.Foo.sln.targets”. The contents of this new file should look like this. Make sure this new file gets checked-in to source control.

    The second part, letting each project control its output folder structure, is simply a matter of adding a line to the project’s *.csproj or *.vbproj file (depending on the language). Locate the first element inside the project file that doesn’t have a Condition attribute specified, and the locate the corresponding closing tag for this element. Immediately above the closing tag add a line something like this:

    <OutDir Condition=" '$(PreferredOutDir)' != '' ">$(PreferredOutDir)$(MSBuildProjectName)\</OutDir>

    In this example the project will output to the Team Build drop folder under a subfolder named the same as the project file (without the .csproj extension). You might choose a different pattern. Also, Web projects usually create their own output folder under a _PublishedWebSites subfolder of the Team Build drop folder, to maintain this behaviour just set the OutDir property to equal the PreferredOutDir property exactly.

    You can verify if your changes have worked on your local machine before checking in simply by running MSBuild from the command-line and specifying the OutDir property just like Team Build does, eg:

    msbuild Foo.sln /p:OutDir=c:\TestDropFolder\

    0 讨论(0)
  • 2020-11-30 19:22

    Simple Solution:

    Replace all <SolutionToBuild> nodes with <SolutionToPublish>. This will of course only work for publishable projects (e.g. Web projects and applications), not for library projects.

    As simple as that :)

    0 讨论(0)
  • 2020-11-30 19:25

    Sling this in a propertygroup:

    <CustomizableOutDir>true</CustomizableOutDir>
    

    It'll override the global 'CustomizableOutDir' property which, by default, is set to False. Setting this in the SolutionToBuild's properties will not work.

    0 讨论(0)
  • 2020-11-30 19:31

    By default each project file (*.csproj, *.vbproj, etc.) specifies a default output directory (which is usually bin\Debug, bin\Release, etc.). Team Build actually overrides this so that you're not at the whim of what properties the developer sets in the project file but also so that Team Build can make assumptions about where the outputs are located.

    The easiest way to override this behaviour is to set CustomizableOutDir to true in the SolutionToBuild item group as shown here:

    <ItemGroup>
      <SolutionToBuild Include="$(BuildProjectFolderPath)\path\MySolution.sln" />
        <Properties>CustomizableOutDir=true</Properties>
      </SolutionToBuild>
    </ItemGroup>
    

    This will make the drop folder structure roughly match what you would get locally if you built the solution.

    This method is definitely preferable to overriding the Core* targets which can cause upgrade issues.

    0 讨论(0)
  • 2020-11-30 19:35

    You could have one buildscript per project, that would do exactly what you want. Just create a new TFSBuild file, add the projects you want to have built to the itemgroup(in the order you want them built), set where you want the output to be. This is done by overriding the - property in your TFSBuild file.

    But I also agree with the previous poster - why don't you just run with a single build script, and add a zip-task at the end? Maintaining a buildscript per project does add maintenance overhead...

    0 讨论(0)
提交回复
热议问题