基础操作
- 修改已有属性的值, 如例在DefineConstants值后追加
<CreateProperty Value="$(DefineConstants);PatchCreationId=$(PatchCreationId)">
<Output PropertyName="DefineConstants" TaskParameter="Value"/>
</CreateProperty>
<Exec Command="echo $(LastProductVersion)" Timeout="10000" IgnoreExitCode="true"/>
<Message Text="LastChangedRevision: $(LastChangedRevision)"/>
操作文件和目录
<MakeDir Directories="$(HistoryPath)\$(ProductVersion)"/>
<RemoveDir Directories="patch" />
<Delete Files="@(LatestFiles)" />
<Copy SourceFiles="$(OutputPath)\$(OutputName).msi" DestinationFiles="$(LatestPath)\$(OutputName)$(ProductVersion).msi"/>
<ReadLinesFromFile File="pv">
<Output TaskParameter="Lines" PropertyName="LastProductVersion"/>
</ReadLinesFromFile>
<WriteLinesToFile File="$(ChangesLog)" Lines="$(ProductVersion)" Overwrite="false" />
操作XML
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
修改XML中内容
<!-- 修改appSettings下DBConnectionString的值-->
<File Id="schedule.plugin.config" Name="plugin.config" Source="..\output\plugins\schedule\plugin.config" />
<util:XmlFile Id="schedule.ConfigDBConnectionString" Action="setValue"
ElementPath="/configuration/appSettings/add[\[]@key='DBConnectionString'[\]]/@value"
File="[schedule]\plugin.config"
Value="server=[IP_DB];initial catalog=gtalarm;user id=[DB_USER];password=[DB_PASSWORD];"/>
编译时生成新的GUID
- 首先,引用MSBuild.MyTask.NewGuid
<UsingTask AssemblyFile="$(LibsPath)\MSBuild\MyTask\MSBuild.MyTask.dll" TaskName="MSBuild.MyTask.NewGuid" />
- 如例,调用生成GUID,放入ProductCode变量
<NewGuid><Output TaskParameter="Guid" PropertyName="ProductCode" /></NewGuid>
编译时获取硬盘信息
- 首先,引用MSBuild.MyTask.HardwareInformation
<UsingTask AssemblyFile="..\src\bin\Release\MSBuild.MyTask.dll" TaskName="MSBuild.MyTask.HardwareInformation" />
- 如例,调用HardwareInformation得到硬盘信息放入DiskVolumeSerialNumber变量
<HardwareInformation DiskPath="c:\windows" DiskPropertyName="VolumeSerialNumber">
<Output TaskParameter="DiskPropertyValue" PropertyName="DiskVolumeSerialNumber" />
</HardwareInformation>
参考和引用