Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msbuild SLN and still get separate project outputs?

I have a normal SLN file, and I'm compiling it fine with msbuild from the command line. I do this:

C:\slndir> msbuild /p:OutDir=C:\slnbin\

And it dumps everything into C:\slnbin, except for websites, which get deployed to C:\slnbin_PublishedWebsites\.

What I would like is to not only have all the binaries dropped in the bin dir, but also have each executeable program have it's own "deployed" folder, similar to what each website gets.

So, for example, If I have the following projects: - Common - Lib1 - Service1 - Lib2 - Service2

I wan to get:

  C:\slnbin\ // Everything
  C:\slbin\Deploy\Service1 // Common, Lib1, Service1
  C:\slbin\Deploy\Service2 // Common, Lib2, Service2

I tried doing stuff like "msbuild /p:OutDir=C:\slnbin\$(ProjectName)", but it just treats it as a literal and creates an actual "$(ProjectName)" subdir.

Preferrably, I would not have to modify every individual project and so on.

Is this possible? Easy?

like image 260
MichaelGG Avatar asked Mar 10 '09 02:03

MichaelGG


2 Answers

Like John Saunders said, you need to have a master MSBuild file that handles the process.

Here is a sample using MSBuild Community Tasks : GetSolutionProjects that gets the projects for a given solution

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Package">

  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

  <!-- Specify here, the solution you want to compile-->
  <ItemGroup>
    <Solution Include="C:\slndir\solution.sln"/>
  </ItemGroup>

  <PropertyGroup>
    <Platform>AnyCPU</Platform>
    <Configuration>Debug</Configuration>

    <!-- Your deployment directory -->
    <DeployDir>C:\slbin\Deploy</DeployDir>
  </PropertyGroup>

  <!-- Gets the projects composing the specified solution -->
  <Target Name="GetProjectsFromSolution">
    <GetSolutionProjects Solution="%(Solution.Fullpath)">
      <Output ItemName="ProjectFiles" TaskParameter="Output"/>
    </GetSolutionProjects>
  </Target>

  <Target Name="CompileProject" DependsOnTargets="GetProjectsFromSolution">
    <!-- 
      Foreach project files
        Call MSBuild Build Target specifying the outputDir with the project filename.
    -->
    <MSBuild Projects="%(ProjectFiles.Fullpath)"
             Properties="Platform=$(Platform);
             Configuration=$(Configuration);
             OutDir=$(DeployDir)\%(ProjectFiles.Filename)\"
             Targets="Build">
    </MSBuild>
  </Target>
</Project>
like image 92
Julien Hoarau Avatar answered Sep 25 '22 13:09

Julien Hoarau


You'll have to do this "by hand". Create a master MSBUILD project file that builds the solution, then copies all the solution outputs where it wants them. This is (roughly) how Visual Studio Team Build does it.

like image 41
John Saunders Avatar answered Sep 26 '22 13:09

John Saunders