HostsFile ClassMSBuild Extension Pack Help
Valid TaskActions are:

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

Update (Required: HostEntries Optional: PathToHostsFile, Truncate

Remote Execution Support: No

Inheritance Hierarchy


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

The HostsFile type exposes the following members.


Public methodHostsFile

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.

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="">
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    <Import Project="$(TPath)"/>    
        <HostEntries Include="MyWebService">
            <Comment>The IP address for MyWebService</Comment>
        <HostEntries Include="MyWebSite">
    <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/ entry). -->
        <MSBuild.ExtensionPack.Computer.HostsFile TaskAction="Update"
                                                  Truncate="True" />
        <!-- Update a hosts file in a custom location.  -->
        <MSBuild.ExtensionPack.Computer.HostsFile TaskAction="Update"
                                                  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"
                                                  Comment="This points to the MyInternalHost server." />
See Also