msbuild SLN and still get separate project outputs

2020-05-26 16:54发布

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?

2条回答
小情绪 Triste *
2楼-- · 2020-05-26 17:25

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.

查看更多
趁早两清
3楼-- · 2020-05-26 17:27

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>
查看更多
登录 后发表回答