我正在尝试在 msbuild 中创建一个可重用的目标,遵循中概述的基本模型如何调用同一个 msbuild 目标两次? https://stackoverflow.com/questions/1332731/how-to-invoke-the-same-msbuild-target-twice
我试图传递一个我想解释为列表的属性。我在网上没有找到处理这种情况的例子。据我了解,问题在于 Properties 已经被视为列表项,因此它不喜欢传入列表项。有没有办法让 msbuild 在这里正确打包和解包列表?
Msbuild 抱怨:
error MSB4012: The expression "FilesToZip=@(Scripts)" cannot be used in this context. Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists.
这是一个调用者示例:
<Target Name="BuildMigrationZip">
<MSBuild Projects="BuildZip.msbuild"
Targets="BuildZip"
Properties="FilesToZip=@(Scripts);OutputZipFile=$(MigrationPackageFilePath);OutputFolder=$(MigrationPackagePath);Flatten=true"/>
<Message Text="Created database migration zip: $(MigrationPackageFilePath)" Importance="high"/>
</Target>
和基本目标:
<Target Name="BuildZip">
<MakeDir Directories="$(OutputFolder)"/>
<Zip Files="@(FilesToZip)"
ZipFileName="$(OutputZipFile)"
Flatten="$(Flatten)"
ParallelCompression="false" />
</Target>
我基本上正要回去剪切和粘贴这些内容,尽管我想在这里打包一些拉链。
UPDATE:同样的问题也适用于在可重用目标上设置输入。到目前为止,我的问题解决了原始功能,但保持依赖关系正常工作会很好。例如:
<Target Name="BuildZip"
Inputs="@(FilesToZip)"
Outputs="$(OutputZipFile)">
<MakeDir Directories="$(OutputFolder)"/>
<Zip Files="@(FilesToZip)"
ZipFileName="$(OutputZipFile)"
Flatten="$(Flatten)"
ParallelCompression="false" />
</Target>