[英]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.