简体   繁体   English

msbuild其他项目并将输出复制到当前项目

[英]msbuild other projects and copy output to current project

Here is my code: 这是我的代码:

<ItemGroup>
    <ProjectsToBuild Include="$(ProjectDir)..\proj1.jsproj"/>
    <ProjectsToBuild Include="$(ProjectDir)..\proj2.jsproj"/>
    <!-- ... -->
  </ItemGroup>
  <PropertyGroup>
    <Config>Release</Config>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <Config>Debug</Config>
  </PropertyGroup>
    <Target Name="Build">
        <MSBuild Projects="@(ProjectsToBuild)" 
          ContinueOnError ="false"
          Properties="Configuration=@(Config)">
          <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
        </MSBuild>
        <!-- Need to copy single generated js file in each projects to current project (ie:mainProj\autogenerated folder) -->
    </Target>

So, proj1.jsproj generates proj1.js single file, proj2.jsproj generates proj2.js single file,... 因此,proj1.jsproj生成proj1.js单个文件,proj2.jsproj生成proj2.js单个文件,...

Then I need to copy those files to: 然后,我需要将这些文件复制到:

$(ProjectDir)\\autogenerated\\proj1\\proj1.js $(PROJECTDIR)\\自动生成\\ proj1 \\ proj1.js

$(ProjectDir)\\autogenerated\\proj2\\proj2.js $(PROJECTDIR)\\自动生成\\ proj2 \\ proj2.js

... ...

Thanks in advance for your help. 在此先感谢您的帮助。

This can be achieved in a number of ways, here's one which uses metadata to declare a destination directory, combines build and copy into one target and loops over the ItemGroup calling that target: 这可以通过多种方式来实现,这是一种使用元数据声明目标目录,将构建和复制合并到一个目标并在调用该目标的ItemGroup上循环的一种方式:

<ItemGroup>
  <ProjectsToBuild Include="$(ProjectDir)..\proj1.jsproj">
    <DestDir>proj1</DestDir>
  </ProjectsToBuild>
  <ProjectsToBuild Include="$(ProjectDir)..\proj2.jsproj">
    <DestDir>proj2</DestDir>
  </ProjectsToBuild>
</ItemGroup>

<Target Name="Build">
  <MSBuild Projects="$(MsBuildThisFile)" Targets="BuildAndCopy"
    Properties="ProjectToBuild=%(ProjectsToBuild.Identity);
                DestDir=$(ProjectDir)\autogenerated\%(ProjectsToBuild.DestDir)" />
</Target>

<Target Name="BuildAndCopy">
  <MSBuild Projects="$(ProjectToBuild)" Targets="Build" >
    <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
  </MSBuild>
  <Copy SourceFiles="@(OutputFiles)" DestinationFolder="$(DestDir)"/>
</Target>

Now if your projects are really named like that and your directory structure is like that things can be simplified: the only different part for every project is the name, so you could simply use 现在,如果您的项目真的是这样命名的,那么目录结构就可以简化了:每个项目唯一不同的部分是名称,因此您可以简单地使用

<ItemGroup>
  <ProjectsToBuild Include="proj1">
  <ProjectsToBuild Include="proj2">
</ItemGroup>

and then derive all other paths from it. 然后从中得出所有其他路径。

Another way is importing a common MsBuild file in every project, and make the common file declare a postbuild event to copy $(OutputFile) to $(ProjectDir)\\autogenerated\\$(ProjectName)\\$(OutputFile) or something like that; 另一种方法是在每个项目中导入一个通用的MsBuild文件,并使该通用文件声明一个postbuild事件,以将$(OutputFile)复制到$(ProjectDir)\\ autogenic \\ $(ProjectName)\\ $(OutputFile)或类似的东西; I'm not familiar with js projects so the names might be wrong but you get the idea. 我对js项目不熟悉,因此名称可能是错误的,但是您明白了。 This removes the need for an extra MsBuild file just to build projects. 这消除了仅用于构建项目的额外MsBuild文件的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 msbuild一个引用具有不同配置的项目的项目 - msbuild a project referencing projects with different configurations MSBuild + Visual Studio:为解决方案中的所有项目自定义默认“复制本地” - MSBuild + Visual studio: Customize default “Copy Local” for all projects in the solution 无法使用MSBuild编译带有子Web项目的Web项目 - Unable to compile web project with sub-web-projects with MSBuild 在VS中生成其他解决方案项目的MSBuild任务失败,但可与MSBuild.exe命令行一起使用 - MSBuild task to Build other solution projects fails in VS but works with MSBuild.exe command line 项目是否可以包含Visual Studio的其他项目? - Can a project contain other projects with Visual Studio? 如何复制Visual Studio 2010项目以在其他系统中使用? - How to copy Visual studio 2010 projects to use in other system? 您可以搜索解决方案中的当前项目和所有引用的项目吗? - Can you search in current project and all referenced projects within solution? 具有两个Web项目的MSBuild解决方案 - MSBuild solution with two web projects MSBuild复制问题 - Trouble with MSBuild Copy 如何知道哪些其他项目引用了 Visual Studio 中的某个项目? - How to know which other projects refer to a certain project in Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM