commit e9924e0befa62ad399084be0962844feafa9ba45 Author: Daniel Triendl Date: Wed May 8 14:02:36 2019 +0200 Initial Import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b84f3d --- /dev/null +++ b/.gitignore @@ -0,0 +1,351 @@ + +# Created by https://www.gitignore.io/api/visualstudio +# Edit at https://www.gitignore.io/?templates=visualstudio + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# End of https://www.gitignore.io/api/visualstudio diff --git a/CPABuildEvents.sln b/CPABuildEvents.sln new file mode 100644 index 0000000..739f383 --- /dev/null +++ b/CPABuildEvents.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.352 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPABuildEvents", "CPABuildEvents\CPABuildEvents.csproj", "{2EDFEE33-2BAD-49D3-87AC-C59C42A099D0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2EDFEE33-2BAD-49D3-87AC-C59C42A099D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2EDFEE33-2BAD-49D3-87AC-C59C42A099D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2EDFEE33-2BAD-49D3-87AC-C59C42A099D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2EDFEE33-2BAD-49D3-87AC-C59C42A099D0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {24B05F37-9539-484D-A83F-FF5F970ACE0D} + EndGlobalSection +EndGlobal diff --git a/CPABuildEvents/BuildEventsPackage.cs b/CPABuildEvents/BuildEventsPackage.cs new file mode 100644 index 0000000..0932d6a --- /dev/null +++ b/CPABuildEvents/BuildEventsPackage.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.ObjectModel; +using System.ComponentModel.Design; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Management.Automation; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using EnvDTE; +using EnvDTE80; +using Microsoft.VisualStudio; +using Microsoft.VisualStudio.OLE.Interop; +using Microsoft.VisualStudio.PlatformUI; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.Win32; +using Task = System.Threading.Tasks.Task; + +namespace CPABuildEvents +{ + /// + /// This is the class that implements the package exposed by this assembly. + /// + /// + /// + /// The minimum requirement for a class to be considered a valid package for Visual Studio + /// is to implement the IVsPackage interface and register itself with the shell. + /// This package uses the helper classes defined inside the Managed Package Framework (MPF) + /// to do it: it derives from the Package class that provides the implementation of the + /// IVsPackage interface and uses the registration attributes defined in the framework to + /// register itself and its components with the shell. These attributes tell the pkgdef creation + /// utility what data to put into .pkgdef file. + /// + /// + /// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file. + /// + /// + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] + [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About + [ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] + [Guid(BuildEventsPackage.PackageGuidString)] + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")] + public sealed class BuildEventsPackage : AsyncPackage + { + /// + /// VSPackage1 GUID string. + /// + public const string PackageGuidString = "90d6e709-5902-4603-8f56-3b4cdaaa784f"; + + private readonly Lazy _dte; + private readonly Lazy _events; + private readonly Lazy _buildEvents; + private readonly Lazy _outWindow; + private readonly Lazy _buildPane; + + /// + /// Initializes a new instance of the class. + /// + public BuildEventsPackage() + { + // Inside this method you can place any initialization code that does not require + // any Visual Studio service because at this point the package object is created but + // not sited yet inside Visual Studio environment. The place to do all the other + // initialization is the Initialize method. + _dte = new Lazy(() => ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2); + _events = new Lazy(() => _dte.Value.Events); + _buildEvents = new Lazy(() => _events.Value.BuildEvents); + _outWindow = new Lazy(() => GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow); + _buildPane = new Lazy(() => + { + _outWindow.Value.GetPane(VSConstants.GUID_BuildOutputWindowPane, out var pane); + return pane; + }); + } + + #region Package Members + + /// + /// Initialization of the package; this method is called right after the package is sited, so this is the place + /// where you can put all the initialization code that rely on services provided by VisualStudio. + /// + /// A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down. + /// A provider for progress updates. + /// A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method. + protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) + { + // When initialized asynchronously, the current thread may be a background thread at this point. + // Do any initialization that requires the UI thread after switching to the UI thread. + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + + _buildEvents.Value.OnBuildBegin += DoBuildBegin; + _buildEvents.Value.OnBuildDone += DoBuildEnd; + } + + private void DoBuildEnd(vsBuildScope Scope, vsBuildAction Action) + { + ThreadHelper.ThrowIfNotOnUIThread(); + var solution = _dte.Value.Solution; + if (solution != null) + { + var postBuildScript = Path.Combine(Path.GetDirectoryName(solution.FullName), "_postbuild.ps1"); + if (File.Exists(postBuildScript)) + { + new RunPSScript(postBuildScript, _buildPane.Value).RunScript(); + } + } + } + + private void DoBuildBegin(vsBuildScope Scope, vsBuildAction Action) + { + ThreadHelper.ThrowIfNotOnUIThread(); + var solution = _dte.Value.Solution; + if (solution != null) + { + var preBuildScript = Path.Combine(Path.GetDirectoryName(solution.FullName), "_prebuild.ps1"); + if (File.Exists(preBuildScript)) + { + new RunPSScript(preBuildScript, _buildPane.Value).RunScript(); + } + } + } + + #endregion + } +} diff --git a/CPABuildEvents/BuildEventsPackage.resx b/CPABuildEvents/BuildEventsPackage.resx new file mode 100644 index 0000000..a05ec95 --- /dev/null +++ b/CPABuildEvents/BuildEventsPackage.resx @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + VSPackage1 Extension + + + VSPackage1 Visual Studio Extension Detailed Info + + + Resources\BuildEventsPackage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/CPABuildEvents/CPABuildEvents.csproj b/CPABuildEvents/CPABuildEvents.csproj new file mode 100644 index 0000000..68edadc --- /dev/null +++ b/CPABuildEvents/CPABuildEvents.csproj @@ -0,0 +1,108 @@ + + + + 16.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + true + + + + + + + + Debug + AnyCPU + 2.0 + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {2EDFEE33-2BAD-49D3-87AC-C59C42A099D0} + Library + Properties + CPABuildEvents + CPABuildEvents + v4.7.2 + true + true + true + true + true + true + true + Program + $(DevEnvDir)devenv.exe + /rootsuffix Exp + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + Designer + + + + + + + + + + + + False + ..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll + + + + + + + + compile; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + true + VSPackage + Designer + + + + + + \ No newline at end of file diff --git a/CPABuildEvents/Properties/AssemblyInfo.cs b/CPABuildEvents/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ee3a1fe --- /dev/null +++ b/CPABuildEvents/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CPABuildEvents")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CPABuildEvents")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CPABuildEvents/Resources/BuildEventsPackage.ico b/CPABuildEvents/Resources/BuildEventsPackage.ico new file mode 100644 index 0000000..d323b07 Binary files /dev/null and b/CPABuildEvents/Resources/BuildEventsPackage.ico differ diff --git a/CPABuildEvents/RunPSScript.cs b/CPABuildEvents/RunPSScript.cs new file mode 100644 index 0000000..5c844b8 --- /dev/null +++ b/CPABuildEvents/RunPSScript.cs @@ -0,0 +1,71 @@ +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.Threading; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Management.Automation; +using System.Text; +using Task = System.Threading.Tasks.Task; + +namespace CPABuildEvents +{ + class RunPSScript + { + private string _scriptFile; + private IVsOutputWindowPane _pane; + + public RunPSScript(string scriptFile, IVsOutputWindowPane pane) + { + _scriptFile = scriptFile; + _pane = pane; + } + + public void RunScript() + { + using (var psi = PowerShell.Create()) + { + psi.AddScript(_scriptFile); + psi.Streams.Error.DataAdded += Error_DataAdded; + + var results = psi.Invoke(); + PrintResults(results); + } + } + + private void Error_DataAdded(object sender, DataAddedEventArgs e) + { + var record = ((PSDataCollection)sender)[e.Index]; + + PrintRecordAsync(record); + } + + private async Task PrintRecordAsync(ErrorRecord record) + { + if (_pane == null) + { + return; + } + + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + _pane.OutputString($"{Path.GetFileName(_scriptFile)}: {record}\r\n"); + } + + private void PrintResults(Collection results) + { + if (_pane == null) + { + return; + } + + ThreadHelper.ThrowIfNotOnUIThread(); + foreach (var result in results) + { + _pane.OutputString($"{Path.GetFileNameWithoutExtension(_scriptFile)}: {result}\r\n"); + } + _pane.Activate(); + } + } +} diff --git a/CPABuildEvents/source.extension.vsixmanifest b/CPABuildEvents/source.extension.vsixmanifest new file mode 100644 index 0000000..4f35c96 --- /dev/null +++ b/CPABuildEvents/source.extension.vsixmanifest @@ -0,0 +1,22 @@ + + + + + CPABuildEvents + Run _prebuild.ps1 and _postbuild.ps1 on build start and end + true + + + + + + + + + + + + + + +