Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added VM FileExistsInGuest, GetFileInfoInGuest, RunProgramInGuest MSB…

…uild tasks.

git-svn-id: https://vmwaretasks.svn.codeplex.com/svn/trunk@39424 9b283d60-5439-405e-af05-b73fd8c4d996
  • Loading branch information...
commit 7780edc510d7e70d9b8d398edfe9b56e1aaff6c7 1 parent d7e9679
@dblock authored
View
6 Documentation/WhatsNew.html
@@ -29,8 +29,8 @@
<ul>
<li>Added support for VixCOM 1.8.1. VMWareTasks works against all 1.6.2, 1.7.0, 1.8.0
and 1.8.1 versions.</li>
- <li>Added Vestris.VMWareLib.MSBuildTasks.dll that adds support for MSBuild with a series
- of MSBuild tasks.</li>
+ <li>Added Vestris.VMWareLib.MSBuildTasks.dll that adds support for MSBuild with MSBuild
+ tasks that implement most common functions.</li>
<li>Added <code>Vestris.VMWareLib.VMWareRootSnapshotCollection.RemoveSnapshot</code>
that accepts a configurable timeout.</li>
</ul>
@@ -39,7 +39,7 @@
<ul>
<li><a href="http://vmwaretasks.codeplex.com/WorkItem/View.aspx?WorkItemId=5138">5138</a>:
Tools.Windows.Shell.GetEnvironmentVariables fails with a "File not found" error
- on some x64 systems where "tmp" resolves to a non-existent path.</li>
+ on some x64 systems where %tmp% resolves to a non-existent path.</li>
</ul>
</li>
</ul>
View
3  Source/VMWareLibMSBuildTasks/VMWareLibMSBuildTasks.csproj
@@ -56,6 +56,8 @@
<Compile Include="VirtualMachineCreateTempFileInGuest.cs" />
<Compile Include="VirtualMachineDeleteDirectoryFromGuest.cs" />
<Compile Include="VirtualMachineDeleteFileFromGuest.cs" />
+ <Compile Include="VirtualMachineFileExistsInGuest.cs" />
+ <Compile Include="VirtualMachineGetFileInfoInGuest.cs" />
<Compile Include="VirtualMachineRemoveSnapshot.cs" />
<Compile Include="VirtualMachineLoginGuest.cs" />
<Compile Include="VirtualMachineOpen.cs" />
@@ -64,6 +66,7 @@
<Compile Include="VirtualMachinePowerOff.cs" />
<Compile Include="VirtualMachinePowerOn.cs" />
<Compile Include="VirtualMachineRevertToSnapshot.cs" />
+ <Compile Include="VirtualMachineRunProgramInGuest.cs" />
<Compile Include="VirtualMachineShutdownGuest.cs" />
</ItemGroup>
<ItemGroup>
View
3  Source/VMWareLibMSBuildTasks/Vestris.VMWareLib.MSBuildTasks.Targets
@@ -16,6 +16,9 @@
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineDeleteDirectoryFromGuest" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineDeleteFileFromGuest" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineCreateTempFileInGuest" />
+ <UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineFileExistsInGuest" />
+ <UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineRunProgramInGuest" />
+ <UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineGetFileInfoInGuest" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineCreateSnapshot" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineRevertToSnapshot" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineRemoveSnapshot" />
View
2  Source/VMWareLibMSBuildTasks/VirtualMachineCreateTempFileInGuest.cs
@@ -30,7 +30,7 @@ public int CreateTempFileTimeout
}
/// <summary>
- /// Source path on the guest operating system.
+ /// Temporary file path on the guest operating system.
/// </summary>
[Output]
public string GuestPathName
View
75 Source/VMWareLibMSBuildTasks/VirtualMachineFileExistsInGuest.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Microsoft.Build.Framework;
+using Interop.VixCOM;
+
+namespace Vestris.VMWareLib.MSBuildTasks
+{
+ /// <summary>
+ /// Check whether a file exists in a guest operating system.
+ /// </summary>
+ public class VirtualMachineFileExistsInGuest : VirtualMachineLoginGuest
+ {
+ private int _fileExistsTimeout = VMWareInterop.Timeouts.FileExistsTimeout;
+ private string _guestPathName;
+ private bool _fileExists = false;
+
+ /// <summary>
+ /// Timeout in seconds.
+ /// </summary>
+ public int FileExistsTimeout
+ {
+ get
+ {
+ return _fileExistsTimeout;
+ }
+ set
+ {
+ _fileExistsTimeout = value;
+ }
+ }
+
+ /// <summary>
+ /// File path on the guest operating system.
+ /// </summary>
+ public string GuestPathName
+ {
+ get
+ {
+ return _guestPathName;
+ }
+ set
+ {
+ _guestPathName = value;
+ }
+ }
+
+ /// <summary>
+ /// True if file exists.
+ /// </summary>
+ [Output]
+ public bool FileExists
+ {
+ get
+ {
+ return _fileExists;
+ }
+ }
+
+ public override bool Execute()
+ {
+ using (VMWareVirtualHost host = GetConnectedHost())
+ {
+ using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host))
+ {
+ LoginGuest(virtualMachine);
+ Log.LogMessage(string.Format("Checking file '{0}' in guest os", _guestPathName));
+ _fileExists = virtualMachine.FileExistsInGuest(_guestPathName, _fileExistsTimeout);
+ }
+ }
+
+ return true;
+ }
+ }
+}
View
113 Source/VMWareLibMSBuildTasks/VirtualMachineGetFileInfoInGuest.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Microsoft.Build.Framework;
+using Interop.VixCOM;
+
+namespace Vestris.VMWareLib.MSBuildTasks
+{
+ /// <summary>
+ /// Get file information from a guest operating system.
+ /// </summary>
+ public class VirtualMachineGetFileInfoInGuest : VirtualMachineLoginGuest
+ {
+ private int _getFileInfoTimeout = VMWareInterop.Timeouts.GetFileInfoTimeout;
+ private string _guestPathName;
+ private VMWareVirtualMachine.GuestFileInfo _fileInfo = null;
+
+ /// <summary>
+ /// Timeout in seconds.
+ /// </summary>
+ public int GetFileInfoTimeout
+ {
+ get
+ {
+ return _getFileInfoTimeout;
+ }
+ set
+ {
+ _getFileInfoTimeout = value;
+ }
+ }
+
+ /// <summary>
+ /// File path on the guest operating system.
+ /// </summary>
+ public string GuestPathName
+ {
+ get
+ {
+ return _guestPathName;
+ }
+ set
+ {
+ _guestPathName = value;
+ }
+ }
+
+ /// <summary>
+ /// File size.
+ /// </summary>
+ [Output]
+ public long FileSize
+ {
+ get
+ {
+ return _fileInfo.FileSize;
+ }
+ }
+
+ /// <summary>
+ /// True if the path belongs to a directory.
+ /// </summary>
+ [Output]
+ public bool IsDirectory
+ {
+ get
+ {
+ return _fileInfo.IsDirectory;
+ }
+ }
+
+ /// <summary>
+ /// True if the path belongs to a symbolic link.
+ /// </summary>
+ [Output]
+ public bool IsSymLink
+ {
+ get
+ {
+ return _fileInfo.IsSymLink;
+ }
+ }
+
+ /// <summary>
+ /// Date/time when the file was last modified.
+ /// </summary>
+ [Output]
+ public string LastModified
+ {
+ get
+ {
+ return _fileInfo.LastModified.HasValue
+ ? _fileInfo.LastModified.Value.ToString()
+ : string.Empty;
+ }
+ }
+
+ public override bool Execute()
+ {
+ using (VMWareVirtualHost host = GetConnectedHost())
+ {
+ using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host))
+ {
+ LoginGuest(virtualMachine);
+ Log.LogMessage(string.Format("Retreiving file information for '{0}' from guest os", _guestPathName));
+ _fileInfo = virtualMachine.GetFileInfoInGuest(_guestPathName, _getFileInfoTimeout);
+ }
+ }
+
+ return true;
+ }
+ }
+}
View
166 Source/VMWareLibMSBuildTasks/VirtualMachineRunProgramInGuest.cs
@@ -0,0 +1,166 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Microsoft.Build.Framework;
+using Interop.VixCOM;
+
+namespace Vestris.VMWareLib.MSBuildTasks
+{
+ /// <summary>
+ /// Execute a program in the guest operating system.
+ /// </summary>
+ public class VirtualMachineRunProgramInGuest : VirtualMachineLoginGuest
+ {
+ private int _runProgramTimeout = VMWareInterop.Timeouts.RunProgramTimeout;
+ private string _guestProgramName;
+ private string _commandLineArgs;
+ private VMWareVirtualMachine.Process _process;
+
+ /// <summary>
+ /// Timeout in seconds.
+ /// </summary>
+ public int RunProgramTimeout
+ {
+ get
+ {
+ return _runProgramTimeout;
+ }
+ set
+ {
+ _runProgramTimeout = value;
+ }
+ }
+
+ /// <summary>
+ /// Program name on the guest operating system to run.
+ /// </summary>
+ public string GuestProgramName
+ {
+ get
+ {
+ return _guestProgramName;
+ }
+ set
+ {
+ _guestProgramName = value;
+ }
+ }
+
+ /// <summary>
+ /// Command-line arguments.
+ /// </summary>
+ public string CommandLineArgs
+ {
+ get
+ {
+ return _commandLineArgs;
+ }
+ set
+ {
+ _commandLineArgs = value;
+ }
+ }
+
+ /// <summary>
+ /// Process ID.
+ /// </summary>
+ [Output]
+ public long ProcessId
+ {
+ get
+ {
+ return _process.Id;
+ }
+ }
+
+ /// <summary>
+ /// Process name.
+ /// </summary>
+ [Output]
+ public string ProcessName
+ {
+ get
+ {
+ return _process.Name;
+ }
+ }
+
+ /// <summary>
+ /// Process owner.
+ /// </summary>
+ [Output]
+ public string ProcessOwner
+ {
+ get
+ {
+ return _process.Owner;
+ }
+ }
+
+ /// <summary>
+ /// Process start date/time.
+ /// </summary>
+ [Output]
+ public string ProcessStartDateTime
+ {
+ get
+ {
+ return _process.StartDateTime.ToString();
+ }
+ }
+
+ /// <summary>
+ /// Process command line.
+ /// </summary>
+ [Output]
+ public string ProcessCommand
+ {
+ get
+ {
+ return _process.Command;
+ }
+ }
+
+ /// <summary>
+ /// True if process is being debugged.
+ /// </summary>
+ [Output]
+ public bool IsProcessBeingDebugged
+ {
+ get
+ {
+ return _process.IsBeingDebugged;
+ }
+ }
+
+ /// <summary>
+ /// Process exit code for finished processes.
+ /// </summary>
+ [Output]
+ public int ProcessExitCode
+ {
+ get
+ {
+ return _process.ExitCode;
+ }
+ }
+
+ public override bool Execute()
+ {
+ using (VMWareVirtualHost host = GetConnectedHost())
+ {
+ using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host))
+ {
+ LoginGuest(virtualMachine);
+ Log.LogMessage(string.Format("Running '{0}{1}'", _guestProgramName,
+ string.IsNullOrEmpty(_commandLineArgs)
+ ? string.Empty
+ : " " + _commandLineArgs));
+ _process = virtualMachine.RunProgramInGuest(_guestProgramName, _commandLineArgs, 0, _runProgramTimeout);
+ }
+ }
+
+ return true;
+ }
+ }
+}
View
30 Source/VMWareLibMSBuildTasksSamples/Guest.proj
@@ -10,6 +10,7 @@
<CallTarget Targets="CopyFile" />
<CallTarget Targets="Directory" />
<CallTarget Targets="TempFile" />
+ <CallTarget Targets="RunProgram" />
</Target>
<Target Name="LoginGuest">
<VirtualMachineLoginGuest ConnectionType="$(ConnectionType)" Host="$(Host)" HostUsername="$(HostUsername)" HostPassword="$(HostPassword)"
@@ -35,8 +36,35 @@
Filename="$(VmFilename)" GuestUsername="$(GuestUsername)" GuestPassword="$(GuestPassword)">
<Output TaskParameter="GuestPathName" ItemName="CreatedTempFilename" />
</VirtualMachineCreateTempFileInGuest>
- <Message Text="Created @(CreatedTempFilename)" />
+ <VirtualMachineFileExistsInGuest ConnectionType="$(ConnectionType)" Host="$(Host)" HostUsername="$(HostUsername)" HostPassword="$(HostPassword)"
+ Filename="$(VmFilename)" GuestUsername="$(GuestUsername)" GuestPassword="$(GuestPassword)" GuestPathName="@(CreatedTempFilename)">
+ <Output TaskParameter="FileExists" ItemName="CreatedTempFileExists" />
+ </VirtualMachineFileExistsInGuest>
+ <Message Text="Created @(CreatedTempFilename) exists: @(CreatedTempFileExists)" />
+ <VirtualMachineGetFileInfoInGuest ConnectionType="$(ConnectionType)" Host="$(Host)" HostUsername="$(HostUsername)" HostPassword="$(HostPassword)"
+ Filename="$(VmFilename)" GuestUsername="$(GuestUsername)" GuestPassword="$(GuestPassword)" GuestPathName="@(CreatedTempFilename)">
+ <Output TaskParameter="FileSize" ItemName="CreatedTempFileSize" />
+ <Output TaskParameter="LastModified" ItemName="CreatedTempFileLastModified" />
+ <Output TaskParameter="IsDirectory" ItemName="CreatedTempFileIsDirectory" />
+ <Output TaskParameter="IsSymLink" ItemName="CreatedTempFileIsSymLink" />
+ </VirtualMachineGetFileInfoInGuest>
+ <Message Text="Created @(CreatedTempFilename): @(CreatedTempFileSize) bytes, modified @(CreatedTempFileLastModified) [@(CreatedTempFileIsDirectory)/@(CreatedTempFileIsSymLink)]" />
<VirtualMachineDeleteFileFromGuest ConnectionType="$(ConnectionType)" Host="$(Host)" HostUsername="$(HostUsername)" HostPassword="$(HostPassword)"
Filename="$(VmFilename)" GuestUsername="$(GuestUsername)" GuestPassword="$(GuestPassword)" GuestPathName="@(CreatedTempFilename)" />
</Target>
+ <Target Name="RunProgram">
+ <VirtualMachineRunProgramInGuest ConnectionType="$(ConnectionType)" Host="$(Host)" HostUsername="$(HostUsername)" HostPassword="$(HostPassword)"
+ Filename="$(VmFilename)" GuestUsername="$(GuestUsername)" GuestPassword="$(GuestPassword)"
+ GuestProgramName="command.com" CommandLineArgs="/C dir">
+ <Output TaskParameter="ProcessId" ItemName="ProcessId" />
+ <Output TaskParameter="ProcessCommand" ItemName="ProcessCommand" />
+ <Output TaskParameter="ProcessName" ItemName="ProcessName" />
+ <Output TaskParameter="ProcessOwner" ItemName="ProcessOwner" />
+ <Output TaskParameter="ProcessStartDateTime" ItemName="ProcessStartDateTime" />
+ <Output TaskParameter="IsProcessBeingDebugged" ItemName="IsProcessBeingDebugged" />
+ <Output TaskParameter="ProcessExitCode" ItemName="ProcessExitCode" />
+ </VirtualMachineRunProgramInGuest>
+ <Message Text="@(ProcessId): command=@(ProcessCommand), name=@(ProcessName), owner=@(ProcessOwner)" />
+ <Message Text=" started @(ProcessStartDateTime), debugged=@(IsProcessBeingDebugged), exitcode=@(ProcessExitCode)" />
+ </Target>
</Project>
View
11 VMWareTasks.proj
@@ -38,9 +38,10 @@
<MSBuild Projects="VMWareTasks.sln" />
</Target>
<ItemGroup>
- <SourceCodeProjects Include="*.sln" />
- <SourceCodeProjects Include="*.proj" />
- <SourceCodeProjects Include="*.cmd" />
+ <SourceCodeProjects Include="VMWareTasks.sln" />
+ <SourceCodeProjects Include="Version.proj" />
+ <SourceCodeProjects Include="VMWareTasks.proj" />
+ <SourceCodeProjects Include="build.cmd" />
</ItemGroup>
<ItemGroup>
<SourceCodeFiles Include="Source/**/*.cs" />
@@ -79,6 +80,9 @@
<ItemGroup>
<DocumentationFiles Include="Documentation/$(Configuration)/VMWareTasks.chm" />
</ItemGroup>
+ <ItemGroup>
+ <LicenseFiles Include="Source/License.txt" />
+ </ItemGroup>
<Target Name="zip" DependsOnTargets="version">
<Copy SourceFiles="@(SourceCodeProjects)" DestinationFolder="$(ReleaseDir)\$(Major).$(Minor)\Source\%(RecursiveDir)" />
<Copy SourceFiles="@(SourceCodeFiles)" DestinationFolder="$(ReleaseDir)\$(Major).$(Minor)\Source\Source\%(RecursiveDir)" />
@@ -86,6 +90,7 @@
<Copy SourceFiles="@(JavaBinaryFiles)" DestinationFolder="$(ReleaseDir)\$(Major).$(Minor)\JavaBin" />
<Copy SourceFiles="@(ArticleFiles)" DestinationFolder="$(ReleaseDir)\$(Major).$(Minor)\Article\%(RecursiveDir)" />
<Copy SourceFiles="@(DocumentationFiles)" DestinationFolder="$(ReleaseDir)\$(Major).$(Minor)" />
+ <Copy SourceFiles="@(LicenseFiles)" DestinationFolder="$(ReleaseDir)\$(Major).$(Minor)" />
<TemplateFile Template="Documentation\WhatsNew.html" OutputFilename="..\$(ReleaseDir)\$(Major).$(Minor)\WhatsNew.html" Tokens="@(AssemblyInfoTokens)" />
<CreateItem Include="$(ReleaseDir)/**/*">
<Output TaskParameter="Include" ItemName="PackageFiles" />
Please sign in to comment.
Something went wrong with that request. Please try again.