HostsFile ClassMSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

SetHostEntry (Required: HostName, IPAddress Optional: Comment, PathToHostsFile)

Update (Required: HostEntries Optional: PathToHostsFile, Truncate

Remote Execution Support: No

Inheritance Hierarchy

SystemObject
  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.ComputerHostsFile

Namespace: MSBuild.ExtensionPack.Computer
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The HostsFile type exposes the following members.

Constructors

  NameDescription
Public methodHostsFile
Top
Properties

  NameDescription
Public propertyComment
The comment after the hosts entry. Only used by the SetHostEntry task action.
Public propertyHostEntries
The list of hosts entries. The identity should be the host name. The IP address should be in the IPAddress metadata. A comment about the entry should be in the Comment metadata. The task will fail if the identity or IPAddress metadata are empty.
Public propertyHostName
The hostname to alias. Only used by the SetHostEntry task action.
Public propertyIPAddress
The IP address for the hosts entry being aliased. Required. Only used by the SetHostEntry task action.
Public propertyPathToHostsFile
The path to the hosts file to update. Defaults to %SYSTEMROOT%\system32\drivers\etc\hosts. Task will fail if this file doesn't exist.
Public propertyTruncate
If True, any host entry not in the HostEntries item group will be removed from the hosts file. Default is False. Only used by the Update task action.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>    
    <ItemGroup>
        <HostEntries Include="MyWebService">
            <IPAddress>10.0.0.1</IPAddress>
            <Comment>The IP address for MyWebService</Comment>
        </HostEntries>
        <HostEntries Include="MyWebSite">
            <IPAddress>10.0.0.2</IPAddress>
        </HostEntries>
    </ItemGroup>
    <Target Name="Default">
        <!-- Update the current machine's hosts file.  With Truncate=True, any hosts entries not in @(HostEntries) will
       be deleted (except for the default localhost/127.0.0.1 entry). -->
        <MSBuild.ExtensionPack.Computer.HostsFile TaskAction="Update"
                                                  HostEntries="@(HostEntries)"
                                                  Truncate="True" />
        <!-- Update a hosts file in a custom location.  -->
        <MSBuild.ExtensionPack.Computer.HostsFile TaskAction="Update"
                                                  HostEntries="@(HostEntries)"
                                                  PathToHostsFile="\\SDG-WKS1348\a\hosts" />
        <!-- Update a single host entry.  If the entry doesn't exist, it will be created. -->
        <MSBuild.ExtensionPack.Computer.HostsFile TaskAction="SetHostEntry"
                                                  HostName="MyInternalHost"
                                                  IPAddress="10.0.0.3"
                                                  Comment="This points to the MyInternalHost server." />
    </Target>
</Project>
See Also

Reference