OnBuildBegin does not fire in Visual Studio Macro until I run it from Macro Explorer - envdte

I have the following Visual Studio Macro:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports MyMacros.EnvironmentEvents
Imports System.Diagnostics
Public Module Module1
Private WithEvents buildEvents As EnvDTE.BuildEvents = EnvironmentEvents.BuildEvents
Public Sub BuildEvents_OnBuildBegin() Handles buildEvents.OnBuildBegin
Dim projectItem As ProjectItem = DTE.Solution.FindProjectItem("T4MVCVB.tt")
projectItem.Save()
End Sub
End Module
I can run it from the Macro explorer, and it works great, and after i have double clicked it from the macro explorer and it has run, the eventhandler is invoked on build.
But if I haven't manually run the macro, the eventhandler is never invoked / event is never fired.
What am i missing here?

I put the section in directly in the EnvironmentEvents Module outside the autogenerated region, and now it fires every time.

Related

Registering SignalR - Reference issue?

I am following this tutorial: http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server#groupsfromhub
Having trouble with the first task "How to register SignalR middleware"
In a file called OwinStartup.vb I have...
Imports Microsoft.AspNet.Identity
Imports Microsoft.Owin
Imports Microsoft.Owin.Security.Cookies
Imports Owin
<Assembly: OwinStartup(GetType(MyApplication.Startup))>
Namespace MyApplication
Public Class Startup
Public Sub Configuration(app As IAppBuilder)
' Any connection or hub wire up and configuration should go here
app.MapSignalR()
End Sub
End Class
End Namespace
VS 2013 does not like this line: app.MapSignalR() It is telling me: 'MapSignalR' is not a member of 'Owin.IAppBuilder'
I think I have all the required references added. Any ideas?
If you do not add a Hub as a first thing, and go straight to the Startup class, I think you'll miss some references. The Extension method you are missing is from Microsoft.AspNet.SignalR.Core, make sure it's referenced and try again. Or add a Hub to your project, that will bring down the references you need.

Code inside <script runat=“server”> works well in Debug but not when deployed on local IIS

I've been asked to update an old VB.NET web application and this is not the technology i'm the most comfortable with, being more a desktop guy. Anyway, i'n trying to deal with it!
I'm facing a problem I can't solve (please forgive me if the question is weird). First of all, the code works well in production as this is the client source code. It also works well in VS when i launch the site in debug mode. As soon as I publish the website to my local IIS, the page fails
The App_Code folder contains a Database.vb files, containing a Database class, with the following method :
Option Strict On
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Caching
Imports System.Collections
Public Class Database
Public Shared Sub ExecuteDataTable(ByVal strSQL As String, ByRef dt As DataTable)
...
End SUb
I have an ASPX page containing the following code
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadGrid()
End Sub
Private Sub LoadGrid()
Dim strSQL As String = "sp_XXXXXXXXXXXXXXXXXXX"
Dim dt As New System.Data.DataTable
Database.ExecuteDataTable(strSQL, dt)
grd_Data.DataSource = dt
grd_Data.DataBind()
End Sub
</script>
Everything works fine in local debug but as soon as I publish the website on my local IIS7 i get this error :
Server Error in '/' Application.
Compilation Error
Compiler Error Message: BC30456: 'Database' is not a member of '<Default>'.
Line 18: Global.Database.ExecuteDataTable(strSQL, dt)
Notes :
The database class is used everywhere in the project and works fine. only difference I noticed here is that the code is in the aspx file using the script runat="server" instead of the usual .vb file. Not sure it causes the issue as it works well running locally.
I tried to use Global.Database on line 18 but came through the same issue.
The target framework of the solution is v4.0. The application pool in IIS7 is also set to v4.0
Any idea/lead to help me to solve this issue will be greatly appreciated :)
Thanks in advance!
Edit based on corrections:
You need to import the namespace of Database, which by default would be the application namespace.
<%# Import namespace = "myappname" %>

Check namespace

I recently added a class I created with a tool to my Visual Studio 2010 project but I can't call it in my codebehind file. I was told I need to check the namespace. How do I check and control a classes's namespace?
Look at the code files:
Namespace Utilities
Public Class Foo
End Class
End Namespace
Namespace Utilities.Formatting
Public Class DatesAndTimes
End Class
End Namespace
Now, you have to make sure to add the following to any code page:
Imports Utilities
' and/or
Imports Utilities.Formatting
However, you can double-click on MyProject in the solution explorer in Visual Studio, and on the References tab, automatically Import the namespaces you want on all code pages without explicity typing "Imports " on every code page.

Type of member is not CLS-compliant

Using Visual Studio 2008 and VB.Net:
I have a working web app that uses an ASMX web service which is compiled into its separate assembly. I have another class library project compiled as a separate assembly that serves as a proxy to this web service. This all seems to work at runtime but I am getting this warning at compile time which I don't understand and would like to fix:
Type of member 'wsZipeee' is not CLS-compliant
I have dozens of webforms in the main project that reference the proxy class with no compile time complaints as this snippet shows:
Imports System.Data
Partial Class frmZipeee
Inherits System.Web.UI.Page
Public wsZipeee As New ProxyZipeeeService.WSZipeee.Zipeee
Dim dsStandardMsg As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
And yet I have one webform (also in the root of the main project) which gives me the "not CLS-compliant" message but yet attempts to reference the proxy class just like the other ASPX files. I get the compile time warning on the line annoted by me with 'ERROR here..
Imports System.Data
Partial Class frmHome
Inherits System.Web.UI.Page
Public wsZipeee As New ProxyZipeeeService.WSZipeee.Zipeee ERROR here
Dim dsStandardMsg As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
This makes no sense to me. The file with the warning is called frmHome.aspx.vb; all others in the project declare things the same way and have no warning. BTW, the webservice itself returns standard datatypes: integer, string, and dataset.
I traced this problem to the <%# Page declarative of the "problem" file using Codebehind while the other file(s) used the CodeFile attribute. When I changed it, it triggered some new issues but I solved them and in turn the original complaint about nonCLScompliance went away.

How can I debug faster in Visual Studio?

Every time I have to go to attach to process, then scroll down and find w3wp.exe
Is there a faster way to do this?
I have a macro for this very purpose. In the tools menu, open up Macros -> Macros IDE. In the lefthand pane, double-click MyModule (or create a new module) and paste in this code:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module MyModule
Sub AttachToIIS()
Try
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(2) As EnvDTE80.Engine
dbgeng(0) = trans.Engines.Item("T-SQL")
dbgeng(1) = trans.Engines.Item("Managed")
Dim proc2 As EnvDTE80.Process2 = _
dbg2.GetProcesses(trans, Environment.MachineName).Item("w3wp.exe")
proc2.Attach2(dbgeng)
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
End Module
Then, you can edit your keyboard shortcuts and set this to a new combination; I use Ctrl+Shift+A. The command to invoke will be Macros.MyMacros.MyModule.AttachToIIS.
EDITED: changed "COMPUTERNAME" to Environment.MachineName.
You should be able to debug IIS just as if you are using the Visual Studio web server (Cassini):
Show Properties for you ASP.NET project.
Select the Web tab.
In the Servers section select Use Local IIS Web server. Fill in the Project Url.
Run your project in the debugger by hitting F5 (Debug => Start Debugging).
If you are running on Vista or newer with UAC enabled you will have to run Visual Studio as administrator for this to work. Right click on the Visual Studio shortcut and select Run as Administrator.... Accept the prompt to elevate priviledges.
Debug->Attach to Process
Start typing the name of the process "w3wp" and it will immediately find it in the list.
You could write a macro and assign it to a toolbar button.

Resources