'Visual Studio 2010 VB.NET Macros
'www.expressionsoftware.com
'v11.8.1
Imports System
Imports System.Collections.Generic
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Public Module ExpressionSoftwareMacros
Sub PrintFilenamesForOpenFiles()
Dim output = "macro: PrintFilenamesForOpenFiles" + vbCrLf
Dim outputFiles As String
Dim openFiles = GetOpenFiles()
'openFiles.Sort() 'error: failed to compare two elements in the array
openFiles.Sort(New EnvDteDocumentComparerClass())
For Each file In openFiles
outputFiles += "file: " + file.FullName + vbCrLf
Next
output += "date: " + Date.Now + vbCrLf
output += "count: " + Str(openFiles.Count) + vbCrLf
output += outputFiles
Out(output)
End Sub
Sub HideLinebreakToBrace()
Dim output = "macro: HideLinebreakToBrace" + vbCrLf
Dim count = 0
'vs pofs regex
':b whitespace or tab
'Dim searchString = ":b*\n:b*\{" 'matches "\b\n{" which cannot be hidden, can use if count is not output, else count incorrect
Dim searchString = "{:b+\n:b*\{}|{:b*\n:b+\{}"
DTE.Find.FindWhat = searchString
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument 'search current file only
DTE.Find.Action = vsFindAction.vsFindActionFind
DTE.Find.MatchInHiddenText = True
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr 'regex search
DTE.SuppressUI = False
DTE.ActiveDocument.Selection.StartOfDocument() 'set cursor top of file
While DTE.Find.Execute() <> vsFindResult.vsFindResultNotFound
count += 1
DTE.ActiveDocument.Selection.CharLeft(True, 1) 'unselect brace char
DTE.ExecuteCommand("Edit.HideSelection")
End While
DTE.ActiveDocument.Selection.StartOfDocument()
output += "date: " + Date.Now + vbCrLf
output += "file: " + DTE.ActiveDocument.FullName + vbCrLf
output += "count: " + Str(count)
Out(output)
End Sub
Private Function GetOpenFiles() As List(Of EnvDTE.Document)
Dim openFiles As New List(Of EnvDTE.Document)
For Each doc As EnvDTE.Document In DTE.Documents
If doc.ProjectItem IsNot Nothing Then 'todo: combine
If doc.ProjectItem.IsOpen() Then
openFiles.Add(doc)
End If
End If
Next
Return openFiles
End Function
Private Sub Out(ByVal output)
GetMacrosOutputWindow().OutputString(output)
End Sub
'requires Microsoft Samples Utilities module,
'copy module into MyMacros project
Private Function GetMacrosOutputWindow() As OutputWindowPane
Dim windowTitle = "Expression Software Macros"
Dim window As Window
Dim target As Object
Dim document As EnvDTE.Document
window = DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
If DTE.ActiveWindow Is window Then
target = window.Object
Else
target = Utilities.GetOutputWindowPane(windowTitle)
target.clear()
End If
Return target
End Function
End Module
Public Class EnvDteDocumentComparerClass
Implements IComparer(Of EnvDTE.Document)
'compare docs by full filename, for sorting
Function Compare(ByVal file1 As EnvDTE.Document, _
ByVal file2 As EnvDTE.Document) _
As Integer Implements IComparer(Of EnvDTE.Document).Compare
Return file1.FullName.CompareTo(file2.FullName)
End Function
End Class
Public Class EnvDteDocumentComparableClass
Implements IComparable(Of EnvDTE.Document)
'compare docs by full filename, for sorting
Function CompareTo(ByVal other As EnvDTE.Document) _
As Integer Implements IComparable(Of EnvDTE.Document).CompareTo
Return FullName.CompareTo(other.FullName)
End Function
End Class
'**************************************************************
'Misc
'DTE.Documents.Count includes closed docs
'DTE.ActiveDocument.FullName
'output += "date: " + Date.Now + vbCrLf
'Microsoft.VisualBasic.Constants.vbCrLf
'DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
'keyboard shortcuts
' alt + F8 macro explorer
' alt + F11 macros ide
'**************************************************************
Showing posts with label 2010. Show all posts
Showing posts with label 2010. Show all posts
8/1/11
Visual Studio 2010 VB.NET Macros
1/15/11
ASP.NET MVC 3 - Project Template for Visual Studio 2010
References
Microsoft.CSharp
System
System.Core
System.Web
System.Web.Helpers
System.Web.Mvc
System.Web.Routing
System.Web.Services
System.Web.WebPages
Folders
controllers
js
models
properties
ux
views
views\home
views\shared
Files
controllers\homeController.cs
demo.csproj
demo.csproj.user
global.asax
global.asax.cs
js\alert.js
properties\assemblyInfo.cs
ux\style.css
views\_viewStart.cshtml
views\home\default.cshtml
views\shared\error.cshtml
views\shared\_layout.cshtml
views\web.config
web.config
web.debug.config
web.release.config
controllers\homeController.cs
demo.csproj
demo.csproj.user
global.asax
global.asax.cs
js\alert.js
properties\assemblyInfo.cs
ux\style.css
views\_viewStart.cshtml
views\home\default.cshtml
views\shared\error.cshtml
views\shared\_layout.cshtml
views\web.config
web.config
web.debug.config
web.release.config

Microsoft.CSharp
System
System.Core
System.Web
System.Web.Helpers
System.Web.Mvc
System.Web.Routing
System.Web.Services
System.Web.WebPages
Folders
controllers
js
models
properties
ux
views
views\home
views\shared
Files
controllers\homeController.cs
demo.csproj
demo.csproj.user
global.asax
global.asax.cs
js\alert.js
properties\assemblyInfo.cs
ux\style.css
views\_viewStart.cshtml
views\home\default.cshtml
views\shared\error.cshtml
views\shared\_layout.cshtml
views\web.config
web.config
web.debug.config
web.release.config
controllers\homeController.cs
using System.Web.Mvc;
namespace Demo.Controllers
{
public class HomeController : Controller
{
public ActionResult Default()
{
ViewBag.Message = "ViewBag.Message, set in HomeController";
return View();
}
}
}
demo.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion></ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A8C1B3E9-6897-4456-A450-2662343B9E6F}</ProjectGuid>
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>properties</AppDesignerFolder>
<RootNamespace>Demo</RootNamespace>
<AssemblyName>demo</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PublishDatabases>false</PublishDatabases>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Web.WebPages" />
</ItemGroup>
<ItemGroup>
<Compile Include="global.asax.cs">
<DependentUpon>global.asax</DependentUpon>
</Compile>
<Compile Include="properties\assemblyInfo.cs" />
<Compile Include="controllers\homeController.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="global.asax" />
<Content Include="js\alert.js" />
<Content Include="ux\style.css" />
<Content Include="views\_viewStart.cshtml" />
<Content Include="views\home\default.cshtml" />
<Content Include="views\shared\_layout.cshtml" />
<Content Include="views\shared\error.cshtml" />
<Content Include="views\web.config" />
<Content Include="web.config" />
<Content Include="web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</Content>
<Content Include="web.Release.config">
<DependentUpon>web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="models\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>1234</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl></IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://dev.mvcdemo.com/</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
demo.csproj.user
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<StartPageUrl></StartPageUrl>
<StartAction>NoStartPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram></ExternalProgram>
<StartExternalURL></StartExternalURL>
<StartCmdLineArguments></StartCmdLineArguments>
<StartWorkingDirectory></StartWorkingDirectory>
<EnableENC>False</EnableENC>
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
global.asax
<%@ Application Codebehind="global.asax.cs" Inherits="Demo.MvcApplication" Language="C#" %>
global.asax.cs
using System.Web.Mvc;
using System.Web.Routing;
namespace Demo
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", // Parameter defaults
action = "Default",
id = UrlParameter.Optional }
);
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
}
js\alert.js
//<script src="/js/alert.js" type="text/javascript"></script>
alert("/js/alert.js");
properties\assemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("MVC Demo")]
[assembly: AssemblyCompany("Expression Software")]
[assembly: ComVisible(false)]
[assembly: Guid("28bf9b70-c4f2-4007-986f-5598dd52dfa8")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
ux\style.css
body{
background:#000;
color:#fff;
font-family:Verdana, Arial, Helvetica, Sans-Serif;
}
views\_viewStart.cshtml
@*file: \views\_viewStart.cshtml
desc: common view code, executed at the start of View render
*@
@{
//set default layout
Layout = "~/views/shared/_layout.cshtml";
}
views\home\default.cshtml
@{
ViewBag.PageTitle = null; //breakpoint
ViewBag.PageTitle += "MVC Demo";
}
@*html body - view source for line breaks & whitespace*@
<h1>@ViewBag.PageTitle</h1>
ViewBag.PageTitle: @ViewBag.PageTitle<br />
ViewBag.Message: @ViewBag.Message
views\shared\error.cshtml
@{
Layout = null;
}
<!doctype html>
<html>
<head>
<title>Error</title>
<meta charset=utf-8>
</head>
<body>
error...
</body>
</html>
views\shared\_layout.cshtml
<!doctype html>
<html>
<head>
<title>@ViewBag.PageTitle - Expression Software</title>
<meta charset=utf-8>
<link href="/ux/style.css" rel="stylesheet" type="text/css" />
<!--<script src="/js/alert.js" type="text/javascript"></script>-->
</head>
<body>
@RenderBody()
<br />------------------------<br />
@DateTime.Now.ToString("MM-dd-yy HH:mm:ss:fff")
<br />------------------------
@foreach(var x in new [] {0,1,2})
{
;<br />@x; //use leading semicolon to prevent generating extra, collapsed, whitespace
}
</body>
</html>
views\web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
<!-- Enabling request validation in view pages would cause validation to occur after the input has already been processed by the controller.
By default MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a controller or action. -->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add tagPrefix="mvc" namespace="System.Web.Mvc" assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler"
path="*" verb="*"
preCondition="integratedMode"
type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="None" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
web.debug.config
<?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> </configuration>
web.release.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>

Subscribe to:
Posts (Atom)