Skip to content

Commit

Permalink
Added Custom.targets for generating and including a standard VersionA…
Browse files Browse the repository at this point in the history
…ssemblyInfo file using MSBuildTasks nuget package

Tidied up AssemblyInfo for each project to remove errors, and update some data
Removed packages from repository
added nuget exe
modified build.ps1 to restore nuget, get version from dll to rename the installer
Fixed SSMS addin from failing due to resource name being wrong when creating template file
Added new SSMS versions - 2012, 2014, 2016 (untested)
Minor code cleanups with Laan.AddIns.Ssms
  • Loading branch information
benlaan committed Jan 25, 2017
1 parent 9b1d60b commit d3e6374
Show file tree
Hide file tree
Showing 97 changed files with 325 additions and 104,290 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -9,3 +9,5 @@ node_modules
*/publish/
.cr
/.vs/config/applicationhost.config
/Build/VersionAssemblyInfo.cs
/dist
Binary file added .nuget/NuGet.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions .nuget/nuget.config
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true" />
</packageRestore>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
61 changes: 61 additions & 0 deletions Build/Common.targets
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildCommunityTasksPath>$(SolutionDir)packages\MSBuildTasks.1.5.0.235\tools\</MSBuildCommunityTasksPath>
</PropertyGroup>

<Import Project="$(MSBuildCommunityTasksPath)MSBuild.Community.Tasks.targets"/>

<!-- Default Properties shared by All Projects, for both Debug and Release Configurations -->
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
<WarningLevel>4</WarningLevel>
<ErrorReport>prompt</ErrorReport>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>

<!-- Properties shared by All Projects, for Debug Configuration -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>

<!-- Properties shared by All Projects, for Release Configuration -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<DefineConstants>CODE_ANALYSIS;TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<!--RunCodeAnalysis>true</RunCodeAnalysis-->
</PropertyGroup>

<PropertyGroup>
<Major>0</Major>
<Minor>2</Minor>
<Build>1</Build>
<Revision>$(BUILD_NUMBER)</Revision>
</PropertyGroup>

<Target Name="GenerateVersionAssemblyInfo">
<Message Text="Generating Assembly Version: $(Major).$(Minor).$(Build).$(Revision)"/>
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(SolutionDir)Build\VersionAssemblyInfo.cs"
AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
AssemblyConfiguration="$(Configuration)"
Condition="$(Revision) != '' " />
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(SolutionDir)Build\VersionAssemblyInfo.cs"
AssemblyVersion="$(Major).$(Minor).*"
AssemblyConfiguration="$(Configuration)"
Condition="$(Revision) == '' " />
</Target>

<Target Name="BeforeBuild">
<CallTarget Targets="GenerateVersionAssemblyInfo" />
</Target>
</Project>
68 changes: 33 additions & 35 deletions Laan.AddIns.Ssms/Action.cs
@@ -1,6 +1,5 @@
using System;
using EnvDTE;
using Laan.AddIns.Ssms.Actions;

using Microsoft.Win32;

namespace Laan.AddIns.Core
Expand All @@ -12,7 +11,7 @@ public abstract class Action
/// <summary>
/// Initializes a new instance of the Action class.
/// </summary>
public Action( AddIn addIn )
public Action(AddIn addIn)
{
AddIn = addIn;
}
Expand Down Expand Up @@ -50,14 +49,14 @@ public Action( AddIn addIn )

public string FullName
{
get { return String.Format( "Laan.AddIns.Core.Addin.{0}", KeyName ); }
get { return String.Format("Laan.AddIns.Core.Addin.{0}", KeyName); }
}

protected bool PageExists(string category, string page)
{
try
{
AddIn.TextDocument.DTE.get_Properties( category, page );
AddIn.TextDocument.DTE.get_Properties(category, page);
return true;
}
catch
Expand All @@ -67,78 +66,77 @@ protected bool PageExists(string category, string page)
}

// Because SMSS doesn't appear to allow custom properties to be defined, use Registry instead
protected T ReadConfigValue<T>( string name, T defaultValue )
protected T ReadConfigValue<T>(string name, T defaultValue)
{
using ( var laanSoftwareKey = Registry.CurrentUser.CreateSubKey( "Laan Software" ) )
using (var laanSoftwareKey = Registry.CurrentUser.CreateSubKey("Laan Software"))
{
using ( var smssAddinKey = laanSoftwareKey.CreateSubKey( "SMSS Addin" ) )
using (var smssAddinKey = laanSoftwareKey.CreateSubKey("SMSS Addin"))
{
object obj = smssAddinKey.GetValue( name );
object obj = smssAddinKey.GetValue(name);

if ( obj != null && smssAddinKey.GetValueKind( name ) == RegistryValueKind.String && typeof(T) == typeof(string) )
return (T) obj;
if (obj != null && smssAddinKey.GetValueKind(name) == RegistryValueKind.String && typeof(T) == typeof(string))
return (T)obj;

return defaultValue;
}
}
}
protected bool ReadConfigValue( string name, bool defaultValue )
}

protected bool ReadConfigValue(string name, bool defaultValue)
{
using ( var laanSoftwareKey = Registry.CurrentUser.CreateSubKey( "Laan Software" ) )
using (var laanSoftwareKey = Registry.CurrentUser.CreateSubKey("Laan Software"))
{
using ( var smssAddinKey = laanSoftwareKey.CreateSubKey( "SMSS Addin" ) )
using (var smssAddinKey = laanSoftwareKey.CreateSubKey("SMSS Addin"))
{
object obj = smssAddinKey.GetValue( name );
object obj = smssAddinKey.GetValue(name);

if ( obj != null && smssAddinKey.GetValueKind( name ) == RegistryValueKind.DWord )
return Convert.ToBoolean( obj );
if (obj != null && smssAddinKey.GetValueKind(name) == RegistryValueKind.DWord)
return Convert.ToBoolean(obj);

return defaultValue;
}
}
}

protected void WriteConfigValue<T>( string name, T value )
protected void WriteConfigValue<T>(string name, T value)
{
using ( var laanSoftwareKey = Registry.CurrentUser.CreateSubKey( "Laan Software" ) )
using (var laanSoftwareKey = Registry.CurrentUser.CreateSubKey("Laan Software"))
{
using ( var smssAddinKey = laanSoftwareKey.CreateSubKey( "SMSS Addin" ) )
using (var smssAddinKey = laanSoftwareKey.CreateSubKey("SMSS Addin"))
{
if (typeof(T) == typeof(string))
smssAddinKey.SetValue(name, value, RegistryValueKind.String);
else if (typeof(T) == typeof(bool))
smssAddinKey.SetValue( name, value, RegistryValueKind.DWord );
smssAddinKey.SetValue(name, value, RegistryValueKind.DWord);
}
}

}

protected T ReadProperty<T>( string category, string page, string property, T defaultValue )
protected T ReadProperty<T>(string category, string page, string property, T defaultValue)
{
try
{
var prop = AddIn.TextDocument.DTE.get_Properties( category, page );
return ( T )prop.Item( property ).Value;

var prop = AddIn.TextDocument.DTE.get_Properties(category, page);
return (T)prop.Item(property).Value;
}
catch ( Exception ex )
catch (Exception ex)
{
AddIn.Error( String.Format("Failed to ReadProperty('{0}', '{1}', '{2}')", category, page, property), ex );
AddIn.Error(String.Format("Failed to ReadProperty('{0}', '{1}', '{2}')", category, page, property), ex);
return defaultValue;
}
}

protected void WriteProperty<T>( string category, string page, string property, T value )
protected void WriteProperty<T>(string category, string page, string property, T value)
{
try
{
var prop = AddIn.TextDocument.DTE.get_Properties( category, page );
prop.Item( property ).Value = value;
var prop = AddIn.TextDocument.DTE.get_Properties(category, page);
prop.Item(property).Value = value;
}
catch ( Exception ex )
catch (Exception ex)
{
AddIn.Error( String.Format("Failed to WriteProperty('{0}', '{1}', '{2}')", category, page, property), ex );
AddIn.Error(String.Format("Failed to WriteProperty('{0}', '{1}', '{2}')", category, page, property), ex);
}
}

Expand Down
21 changes: 7 additions & 14 deletions Laan.AddIns.Ssms/Actions/DropDownList.cs
Expand Up @@ -78,8 +78,6 @@ private void Done()
_editor.SetFocus();
}

#region ListBox Events

private void ListBoxLostFocus(object sender, EventArgs e)
{
Done();
Expand Down Expand Up @@ -124,9 +122,10 @@ private void ListBoxDrawItem(object sender, Form.DrawItemEventArgs e)
}
else
{
var selected = (e.State & System.Windows.Forms.DrawItemState.Selected) > 0;
SolidBrush backBrush = new SolidBrush(selected ? Color.CornflowerBlue : e.BackColor);
e.Graphics.FillRectangle(backBrush, e.Bounds);
var selected = (e.State & Form.DrawItemState.Selected) > 0;

using (SolidBrush backBrush = new SolidBrush(selected ? Color.CornflowerBlue : e.BackColor))
e.Graphics.FillRectangle(backBrush, e.Bounds);

var item = _listBox.Items[e.Index] as Item;

Expand All @@ -146,20 +145,14 @@ private void ListBoxDrawItem(object sender, Form.DrawItemEventArgs e)
}
}

#endregion

protected abstract void ExecuteItem(Item item);
protected abstract IEnumerable<Item> GetItems();

public override bool CanExecute()
{
return (
AddIn.IsCurrentDocumentExtension("sql")
&&
AddIn.CurrentSelection == String.Empty
&&
AddIn.CurrentWord != String.Empty
);
return AddIn.IsCurrentDocumentExtension("sql")
&& AddIn.CurrentSelection == String.Empty
&& AddIn.CurrentWord != String.Empty;
}

public override void Execute()
Expand Down
8 changes: 2 additions & 6 deletions Laan.AddIns.Ssms/Actions/Item.cs
Expand Up @@ -13,12 +13,8 @@ public string TightDescription
{
return String.Join(
"\n",
Name.Split(
new[] { "\n" },
StringSplitOptions.RemoveEmptyEntries
)
);

Name.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)
);
}
}

Expand Down
12 changes: 2 additions & 10 deletions Laan.AddIns.Ssms/Actions/MenuAttribute.cs
Expand Up @@ -7,7 +7,7 @@ public class MenuAttribute : Attribute
public string CommandBar { get; set; }
public string Menu { get; set; }

public MenuAttribute( string commandBar, string menu )
public MenuAttribute(string commandBar, string menu)
{
CommandBar = commandBar;
Menu = menu;
Expand All @@ -16,15 +16,7 @@ public MenuAttribute( string commandBar, string menu )

public class MenuBarToolsMenuAttribute : MenuAttribute
{
public MenuBarToolsMenuAttribute( ) : base( "MenuBar", "Tools" )
{
}
}

public class ResultsMenuAttribute : MenuAttribute
{
public ResultsMenuAttribute()
: base( "SQL Results Messages Tab Context", null )
public MenuBarToolsMenuAttribute() : base("MenuBar", "Tools")
{
}
}
Expand Down
1 change: 0 additions & 1 deletion Laan.AddIns.Ssms/Actions/SqlFormatter.cs
Expand Up @@ -6,7 +6,6 @@

namespace Laan.AddIns.Ssms.Actions
{

[MenuBarToolsMenu]
public class SqlFormatter : Core.Action
{
Expand Down
7 changes: 4 additions & 3 deletions Laan.AddIns.Ssms/AddIn.cs
Expand Up @@ -9,8 +9,11 @@

using EnvDTE;
using EnvDTE80;

using Extensibility;

using Laan.AddIns.Actions;

using Microsoft.VisualStudio.CommandBars;

namespace Laan.AddIns.Core
Expand Down Expand Up @@ -288,8 +291,6 @@ private void PlaceCommandsOnMenus()
{
var contextGUIDS = new object[] { };

//_commands.AddNamedCommand( _addInInstance, "MyCommand", "My Command", "blah", true, 0, ref contextGuids, (int) vsCommandStatus.vsCommandStatusEnabled + (int) vsCommandStatus.vsCommandStatusSupported );

var command = _commands.AddNamedCommand2(
_addIn,
action.KeyName,
Expand All @@ -302,7 +303,7 @@ private void PlaceCommandsOnMenus()
(int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton
);
);

if (command != null)
{
Expand Down
Binary file modified Laan.AddIns.Ssms/AssemblyInfo.cs
Binary file not shown.
Binary file modified Laan.AddIns.Ssms/Laan.AddIns.Core.AddIn
Binary file not shown.

0 comments on commit d3e6374

Please sign in to comment.