我花了很多时间研究MSBuild任务和out目录的问题。 这是我在msbuild文件中的目标任务:
<Target Name="CompileService">
<MSBuild Projects="$(ServiceProj)"
Targets="Clean;Rebuild"
Properties="Configuration=%(BuildConfig.Identity);
OutputPath=..\..\..\..\..\$(OutServiceDirectory)\%(BuildConfig.AppServer)"/>
</Target>
文件转到两个文件夹,一些dll和exe文件转到一个目录,不同的dll转到不同的目录,第一个。
当输出路径如下:
OutputPath = d:\ SomeLocation \ $(PackageTempBackServiceProj)\%(BuildConfig.AppServer)“/&GT;
工作正常。所有文件都转到该文件夹。
问题:我不想硬编码路径。如何编写正确的输出目录。
答案 0 :(得分:0)
如果您查看Microsoft.Common.targets,您将看到Build目标的默认定义定义如下:
<Target
Name="Build"
Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
DependsOnTargets="$(BuildDependsOn)"
Outputs="$(TargetPath)"/>
</Target>
此目标的目的是定义它所依赖的目标并创建输出。因此,如果您希望将所有文件转到一个目录,则必须为/ p:OutputPath =“”指定绝对路径,因为相对路径将相对于每个项目文件。
作为替代解决方案,您不想使用绝对路径,也无法使用/ P参数指定属性,您可以尝试使用以下解决方法:
(1)使用Move Task中的移动任务将MSBuild输出文件合并到一个文件夹中:
<ItemGroup>
<FilesToMove Include="..\..\..\..\..\ $(OutServiceDirectory)\%(BuildConfig.AppServer)\*.dll"/>
</ItemGroup>
<Target Name="CombineOutputFile" AfterTargets="Build">
<Move SourceFiles="@(FilesToMove)" DestinationFolder="${DestinationFolder}" />
</Target>
(2)扩展正常构建的行为以创建正确的输出,请参阅How to get all generated outputs以获取更多详细信息:
<Target Name="Build"
DependsOnTargets="$(BuildDependsOn)"
Outputs="@(AllOutputs->'%(FullPath)')">
<CreateItem Include="$(OutputPath)\**\*">
<Output ItemName="AllOutputs" TaskParameter="Include"/>
</CreateItem>
希望那些人可以帮助你。