我开发了名为 ExportSolution 的自定义 MSBuild 任务,我需要将自定义 enum
PackageType 值传递给它。
PackageType 很简单:
public enum PackageType
{
Managed,
Unmanaged,
Both
}
MSBuild 脚本也很简单:
<Target Name="ExportSolution" DependsOnTargets="BuildTasksDll">
<Message Text="Exporting solution '$(SolutionName)' to '$(SolutionPath)'" />
<ExportSolution SolutionName="$(SolutionName)" PackageType="Both"></ExportSolution>
</Target>
但是为该目标运行脚本时我收到以下错误消息:
error MSB4030: "Both" is an invalid value for the "PackageType" parameter of the "ExportSolution" task. The "PackageType" parameter is of type "Tasks.Common.PackageType".
我应该以哪种格式将值传递给 PackageType 变量以使此代码正常工作?
最佳答案
我会像这样重构 Enum。
public enum PackageType
{
Managed = 0,
Unmanaged = 1,
Both = 2
}
然后我会编辑我的构建脚本以使用整数作为选择方法。
<ExportSolution SolutionName="$(SolutionName)" PackageType=2></ExportSolution>
这可能不是您正在寻找的解决方案,但它可能适合您的需要。
关于c# - 将自定义类型的变量传递给自定义 MSBuild 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16646373/