Skip to content

Commit

Permalink
Closes #28 - Auto Attach Debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
dazinator committed Dec 13, 2015
1 parent a5476a3 commit e7460d7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/DnnPackager/DnnPackager.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>build --envdteversion "14.0" --processid 1008--configuration "Debug" --name "DnnPackager.TestModule" --websitename "DotNetNuke"</StartArguments>
<StartArguments>build --envdteversion "14.0" --processid 5712 --configuration "Debug" --name "DnnPackager.TestModule" --websitename "DotNetNuke" --attach</StartArguments>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/DnnPackager/DotNetNukeWebAppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public bool DeployPackages(FileInfo[] installZips, int retryAttempts, Action<str
// find the worker process.
foreach (WorkerProcess proc in serverManager.WorkerProcesses)
{
if (proc.AppPoolName == AppPoolName)
if (proc.AppPoolName == AppPoolName.ToLowerInvariant())
{

return proc.ProcessId;
Expand Down
6 changes: 6 additions & 0 deletions src/DnnPackager/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CommonOptions
{
[Option('w', "websitename", Required = true, HelpText = "The name of the dnn website in IIS to deploy to.")]
public string WebsiteName { get; set; }

}

public class DeployOptions : CommonOptions
Expand All @@ -35,6 +36,9 @@ public class BuildOptions : CommonOptions
[Option('p', "processid", Required = true, HelpText = "The process id for the running visual studio instance.")]
public int ProcessId { get; set; }

[Option('a', "attach", Required = false, HelpText = "Whether to attach the debugger after the deployment is complete.")]
public bool Attach { get; set; }


}

Expand All @@ -48,6 +52,8 @@ public class Options
[VerbOption("build", HelpText = "Build a visual studio project and deploy the packages to a local DNN website in IIS.")]
public BuildOptions BuildVerb { get; set; }



[HelpOption]
public string GetUsage()
{
Expand Down
30 changes: 22 additions & 8 deletions src/DnnPackager/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,42 @@ namespace DnnPackager
public static class ProcessExtensions
{
public static bool Attach(int processId, EnvDTE.DTE dte, Action<string> logger)
{
{
// Try loop - Visual Studio may not respond the first time.
int tryCount = 5;
while (tryCount-- > 0)
{
try
{
Processes processes = dte.Debugger.LocalProcesses;
var targetProcess = processes.Cast<Process>().FirstOrDefault(proc => proc.ProcessID == processId);
if (targetProcess == null)
Process targetProcess = null;
foreach (Process process in processes)
{
return false;

if (process.ProcessID == processId)
{
targetProcess = process;
}
else
{
logger(String.Format("Skipped process named: {0} with Id {1}.", process.Name, process.ProcessID));
}
}

if (targetProcess != null)
{
logger(String.Format("Attaching to process {0}.", targetProcess.Name));
targetProcess.Attach();
logger(String.Format("Attached to process {0} successfully.", targetProcess.Name));
return true;
}

targetProcess.Attach();
logger(String.Format("Attached to process {0} successfully.", targetProcess.Name));
return true;
return false;

}
catch (COMException)
{
logger(String.Format("Trying to attach to processs.."));
logger(String.Format("Will retry attaching to process in a second.."));
System.Threading.Thread.Sleep(1000);
}
}
Expand Down
42 changes: 30 additions & 12 deletions src/DnnPackager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,66 @@ static int Main(string[] args)
if (!parsed)
{
Console.Write(options.GetUsage());
Environment.Exit(-1);
return -1;
}

FileInfo[] installPackages = null;
DTE dte = null;
bool attachDebugger = false;
DotNetNukeWebAppInfo dnnWebsite = null;

switch (invokedVerb)
{
case "build":
success = BuildProjectAndGetOutputZips((BuildOptions)invokedVerbInstance, out installPackages);
var buildArgs = (BuildOptions)invokedVerbInstance;
success = BuildProjectAndGetOutputZips(buildArgs, out installPackages, out dte);
attachDebugger = buildArgs.Attach;
break;
case "deploy":
installPackages = GetInstallZipsFromDirectory(((DeployOptions)invokedVerbInstance).DirectoryPath);
break;
}

dnnWebsite = GetDotNetNukeWebsiteInfo(invokedVerbInstance.WebsiteName);

if (installPackages != null && installPackages.Any())
{
var dnnWebsite = GetDotNetNukeWebsiteInfo(invokedVerbInstance.WebsiteName);
{
success = DeployToIISWebsite(installPackages, dnnWebsite);
}
else
{

// no packages to install.
// log warning?
LogInfo("No packages to install.");
success = true;
}

if (success)
if (!success)
{
return 0;
return -1;
}
else

if (dte != null && attachDebugger)
{
return -1;

LogInfo("Hooking up your debugger!");
var processId = dnnWebsite.GetWorkerProcessId();
if (!processId.HasValue)
{
LogInfo("Unable to find running worker process. Is your website running!?");
}
ProcessExtensions.Attach(processId.Value, dte, LogInfo);
}

return 0;
}

private static bool BuildProjectAndGetOutputZips(BuildOptions options, out FileInfo[] installPackages)
private static bool BuildProjectAndGetOutputZips(BuildOptions options, out FileInfo[] installPackages, out DTE dte)
{

// Get an instance of the currently running Visual Studio IDE.
installPackages = null;
EnvDTE.DTE dte = null;
dte = null;
string dteObjectString = string.Format("VisualStudio.DTE.{0}", options.EnvDteVersion);
string runningObjectName = string.Format("!{0}:{1}", dteObjectString, options.ProcessId);

Expand All @@ -95,7 +114,6 @@ private static bool BuildProjectAndGetOutputZips(BuildOptions options, out FileI
configurationName = options.Configuration;
}


// dte.Solution.SolutionBuild.Build(true);
var projects = dte.Solution.Projects;
var project = projects.OfType<EnvDTE.Project>().FirstOrDefault(p => p.Name == options.ProjectName);
Expand Down
1 change: 0 additions & 1 deletion src/DnnPackager/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Clide.Resolver" version="2.3.33" targetFramework="net40" />
<package id="CommandLineParser" version="1.9.71" targetFramework="net40" />
<package id="GitVersion.CommandLine" version="3.3.0" targetFramework="net4" developmentDependency="true" />
<package id="Microsoft.Web.Administration" version="7.0.0.0" targetFramework="net40" />
Expand Down
14 changes: 7 additions & 7 deletions src/DnnPackager/tools/ModuleDeployment.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@

if (!$buildConfigName)
{
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
$solBuild = Get-Interface $solution.SolutionBuild ([EnvDTE.SolutionBuild])
$solActiveConfig = Get-Interface $solBuild.ActiveConfiguration ([EnvDTE.SolutionConfiguration])
$buildConfigName = [System.Convert]::ToString($solActiveConfig.Name)
}

if(!$attachFlag)
{
Write-Host "Executing $commandPath iiswebsite $installPackagesPath $websiteName"
& $commandPath "build --envdteversion " $dteVersion "--processid " $processId "--configuration " $buildConfigName "--name " $projectName "--websitename " $iisWebsiteName | Write-Host
Write-Host "Executing build --envdteversion $dteVersion --processid $processId --configuration $buildConfigName --name $projectName --websitename $iisWebsiteName"
& $commandPath "build --envdteversion " $dteVersion "--processid " $processId "--configuration " $buildConfigName "--name " $projectName "--websitename " $iisWebsiteName | Write-Host
}
else
{
Write-Host "Executing $commandPath iiswebsite $installPackagesPath $websiteName"
& $commandPath "build --envdteversion " $dteVersion "--processid " $processId "--configuration " $buildConfigName "--name " $projectName "--websitename " $iisWebsiteName " --attach" | Write-Host
Write-Host "Executing build --envdteversion $dteVersion --processid $processId --configuration $buildConfigName --name $projectName --websitename $iisWebsiteName --attach"
& $commandPath "build --envdteversion " $dteVersion "--processid " $processId "--configuration " $buildConfigName "--name " $projectName "--websitename " $iisWebsiteName " --attach" | Write-Host
}
}

Expand All @@ -36,8 +36,8 @@ function Get-ScriptDirectory {

function Get-Configurations()
{
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
$solBuild = Get-Interface $solution.SolutionBuild ([EnvDTE.SolutionBuild])
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
$solBuild = Get-Interface $solution.SolutionBuild ([EnvDTE.SolutionBuild])
$configs = $solBuild.SolutionConfigurations
$configs = [EnvDTE.SolutionConfigurations]::$solBuild.SolutionConfigurations
return $configs
Expand Down

2 comments on commit e7460d7

@dazinator
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity DnnPackager :: Continuos Build 45 is now running

@dazinator
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity DnnPackager :: Continuos Build 1.1.0-unstable.26 outcome was SUCCESS
Summary: Running Build time: 00:00:12

Please sign in to comment.