What Was I Thinking?

Follies & Foils of .NET Development

  Home  |   Contact  |   Syndication    |   Login
  46 Posts | 0 Stories | 104 Comments | 0 Trackbacks

News

Archives

Post Categories

Check These Out

Gurus

Saturday, January 30, 2010 #

In Visual Studio (2008) Web Site Projects do not support pre/post build events.  Web applications do, but web sites do not.

 

This doesn’t mean you can’t have pre/post build events however.  You just have to be a little creative.

 

In my scenario, I needed a pre-build event to fire. 

1. I added a new class library project to my solution and configured its post build event to execute the pre-build event I wanted. 

2. I added a project dependency on the Web Site of the new class library.

Right click the solution explorer on the solution node.

Select Project Dependencies.

Select the web site in the project list dropdown at the top of the dialog.

Check the new class library project on the list of available projects.

Close the dialog.

Now when my web site builds, it builds my new class library, which in turn executes its post-build event.  The result is custom logic executing before my web site is built.  SUCCESS!


Recently I needed to determine the length of a string and perform a Substring operation on a variable in a DOS Batch (.bat) file.  (Yes, people still use DOS batch files!)

After some Googling and some playing around I came up with the following functions. 

 

:Substring
::Substring(retVal,string,startIndex,length)
:: extracts the substring from string starting at startIndex for the specified length 
 SET string=%2%
 SET startIndex=%3%
 SET length=%4%
 
 if "%4" == "0" goto :noLength
 CALL SET _substring=%%string:~%startIndex%,%length%%%
 goto :substringResult
 :noLength
 CALL SET _substring=%%string:~%startIndex%%%
 :substringResult
 set "%~1=%_substring%"
GOTO :EOF
 
:StrLength
::StrLength(retVal,string)
::returns the length of the string specified in %2 and stores it in %1
set #=%2%
set length=0
:stringLengthLoop
if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop)
::echo the string is %length% characters long!
set "%~1=%length%"
GOTO :EOF

 

To call them:

 

:: get the lenth of the sConfigFileRoot
call:StrLength length %sCFR%

:: extract the suffix
call:Substring suffix,%fileroot%,%length%,0


Thursday, January 28, 2010 #

If you want to run a batch (.bat) file from within Visual Studio, you need to add an external tool.

 

From the Tools menu select External Tools, and then click Add.

Fill out the values as illustrated below:

AddExternalTool AddExternalTool

 

Click OK to close the dialog.

 

Now you can select the bat file to run in solution explorer, and select the Run Batch File command from the Tools menu.  The output of the batch file will be echoed to the output window inside visual studio.


My unit test project uses a app.config file that has external source references to other config files located in my “configuration” folder.  My configuration folder is a sub folder of the unit test project.  When the unit test runs, I need to deploy this folder to the TestResults/Out folder so the app.config can be properly loaded during test execution.

 

Here’s the easiest way to accomplish deploying folders to the TestResults folder:

 

  1. Right click on the .testrunconfig file in your solution explorer.  For me, its LocalTestRun.testrunconfig.
  2. Select Open With and select XML editor
  3. Add a deployment item, specifying the relative path as the file name and an outputdirectory value of the directory name.  In my example, I want to deploy everything in the configuration directory to a folder called configuration in the testrun folder, so I’ve added the following entry:

<Deployment>
  <
DeploymentItem filename="Services\Identity\Claim\ClaimService.Test\configuration\" outputDirectory="configuration\" />
</
Deployment>

Now when my tests execution, Visual Studio copies over all my configuration file entries and is able to load the app.config file successfully.


Saturday, January 09, 2010 #

Found this online, it proved VERY helpful and wanted to pass it along.

Silverlight Error #2104 Could not download the silverlight application in IIS6

If you receive this error while trying to deploy your Silverlight application, make sure you did the following things:

1. Adjust the Content Expiration Setting

You should adjust the content expiration setting to 1 minute. The following procedure outlines how to do this with IIS.

  1. Right-click  your Web Site and select Properties from the context menu.

  2. Select the HTTP Headers tab and click "Enable Content Expiration".

  3. Set the content to expire after 1 minute.

2. Register MIME Types and File Extensions

You must register some MIME types and file extensions so that the browser on the client's system can load the correct handler. You need to add the following types:

Extension

MIME Type

.xap

application/octet-stream

.xaml

application/xaml+xml

The .xap needs to have that mime type, in order to be able to be downloaded.

3. Execute permissions must be Scripts Only.

  1. Right-click  your Web Site and select Properties from the context menu.

  2. Select the Directory tab and change "Execute Permissions" to Script only.

Hope this helps.


Wednesday, November 18, 2009 #

Keynote:

 

HOLY SMOKES!!  Now this is why I came to PDC!  Announced today:  Silverlight 4 Beta.  Printing?  Yep.  Access to Local File System?  Yep.  Want to share your assemblies between SL and native .NET assemblies?  No Problem.  Want access to the clipboard?  COM Interop?  Web Cam & Micrphone?  Done and Done.

 

SketchFlow.. Wha!?!?!  OMG thats a cool prototyping tool.

Sharepoint 2010 is looking like a tour de force.  The ease of development, integration and deployment.  Debugging and sandbox support.  Solutions can be deployed and tested on client OS machines.  Client toolkits uses REST or a Client SDK make it all so attractive.  NICE JOB SHAREPOINT.. NICE JOB.

 

oh yeah.. and then there was this:  Microsoft gives free laptop to PDC 2009 attendees.  Some days its great to be a GEEK.

 

On to Windows Identity Foundation overview. 

Windows Identity Foundation Overview:

Covered the basics of WIF:  Stand up an STS (custom or ADFS), configure your application (RP) to be defended by the tokens issued from your new STS.  Configure the claims to fetch, etc.  WIF Wizards take care of the client configuration, and the WIF http modules will map the incoming token to an Identity, Principal,  and a set of claims.  Optionally you can control authorization logic based on the incoming claims either directly in code or by establishing policy articulated in the RP’s configuration file.  WIF supports Active, Passive and Delegated (ACTAS) scenarios.

Nothing new in this session for me, but I still found the validation to be worth while.

Windows Workflow (Overview and Host Deep Dive)

WF (pronounced dub-eff) 4.0 looks like a great improvement over the 3.0 version.  The product looks highly extensible and powerful, but the overview session was anything but.  Presented by Matt Winkler (Mr. WF) presented a 200 level talk to a bunch of people who were asking “What is Workflow?”.  I have some WF 3x experience, and found it difficult to grasp how the pieces fit together.

 

The follow up session was the “under the hood” of the workflow host, which was surprising interesting and insightful. 

The WF presenters needed a session on “How to build, deploy and debug WF 4.0”.  It would have provided attendees with the skills needed to get going with WF.  For a product line still searching for its user base, I think the WF team missed a great opportunity.

Ask The Experts

Pick a topic,  move to the roundtable filled with experts, and dialog with your peers and gurus.  I sat at the WF table for a while, then moved over to C#. Met two members of the C# dev team.  One, DJ Park, was great to talk with, the other (who shall remain nameless) was an arrogant douchebag.  Tomorrow I’m excited to check out the IntelliTrace stuff in VS2010, but now its time to party down, Geek Style.

 

GeekFest

Wall-to-wall geeks having fun the geek way; there was class video games, air hockey tables, pool tables,  on thz,line sessions of Gears of War, and gaggles of geeks competing in a “Puzzle contest”.  Yeah thats right, they were competing over puzzles.  I enjoyed the video games, pool tables, virtual roller coaster, and free chair massages (I really enjoyed that last one).  Plenty of food and drink, and I’m sure somewhere they were hosting a D&D game, but I can’t confirm that.


Tuesday, November 17, 2009 #

My thoughts and observations of this year’s Microsoft PDC conference in LA.

 

Day 1:

Just registered for the conference.  They had many reps available to move attendees through the registration process.  We arrived early, and had to stand in line for 15 minutes, while all the reps stared blankly back at us; “We don’t open until 7.”  Wow.. Great Customer Service.

 

Let me take this moment to comment on the Conference bag this year.  ITS A CHEAP PIECE OF CRAP.  Literally, it looks like a “reusable” grocery shopping bag, except its so thin, I don’t think it will make it through the conference before it rips; something that’s likely to happen at the most inopportunity time, I’m sure.

 

ok.. I’m on to the “Big Hall” to hear the opening key note.  More to come.

 

Pre-Keynote update:  Having just wandered through miles of hallway, I’m thinking that adding a BUILDING MAP to the updated session list would have been a great idea.   Just a thought.

 

Key Note: Yep, its all about Azure.  Ray Ozzie announced the beta of MS PinPoint, a discovery and procurement site for azure hosted, 3rd Party developed applications (Think AppleStore for your services that you want to sell to others).  Included is an offering, code named “Dallas”.  Dallas is a PinPoint channel that’s all about data.  Want to get access to the US Census data?  Go to The Dallas channel on pinpoint and subscribe to it.  Data is available as data feeds, Restful services, and can even be consumed through ODBC connections.  Any publically available data can be offered through the Dallas channel, and includes the ability for trail and full subscriptions.

other big announcements; VS 2010 has some pretty great debugging and tracing tools. They have included some of the productivity features included in ReSharper, and have a new tool IntelliTrace.  More about this later.

Want to develop Azure services, but run it all locally?  Next year, MS will announce Windows Server 2008 AppFabric.  That’s the ticket. (If they include the .NET services in the fabric, where does that leave the current on-premises solutions like the Biztalk ESB???)

The other big Azure announcement, is a connectivity kit that allows your Azure hosted services to reach into your local premises data stores (using IPv6 and IPSEC tunneling).  NICE!!!

 

More to come.

 

What’s New with C# 4.0 (and some interesting vaporware)…

VB & CS Teams will now synchronize their feature sets (am I the only one who sees a problem with this?)

Dynamic Typing, Declarative programming and Parallel execution, all locked into 4.0 CLR.  You can download the beta bits now.  I must admit I’ve been staying away from Parallel extensions, but they look REALLY interesting and I plan on digging into them a bit. 

and then we saw a demo of some interesting stuff that they “might-possibly-some-day-release-in-a-future-version—but-maybe-not”.

Opening the compiler.  Lets you write your own custom extensions for the compiler and use compiler native types.  This might be good for Tool developers, and opens up the possibility for some interesting aspect oriented stuff, but I don’t think there will be much mainstream interest here.

Simplifying Parallel asynchronous operations.  Using the 4.0 code base its possible to control when threads are returned to the pool during a parallel execution, but its not easy.  They demo’d some simple extension methods which make it OH SO NICE.  I’m hoping this makes it into the 4.x feature set.

I’d write more, but I’ve got to rush off to

 

Lessons Learned Migrating Applications To Windows Azure

This was a panel of companies that had migrated some of their systems to the cloud.  They included B-2-C solutions (like Domino’s Pizza), B-2-B solutions, and Enterprise-only solutions.  The common thread across these early adopters was the desire to support peak loads without having to invest in a self-hosted infrastructure.   All the companies had significant hand-holding from Microsoft, and as of the PDC, none of them had yet gone live.  I didn’t view this as a slam against Azure, but rather the tale of companies cautiously embracing the bleeding edge technologies.

 

Overview of Sharepoint 2010 Programmability:

Having no sharepoint development experience, I thought this might be an interesting presentation for me.  I was right.  Two big take-aways from this presentation.  Number one; if you developed any sharepoint parts, or integration components for earlier versions of sharepoint, you were either insane or foolish.  Sharepoint 2010 takes a big step forward in the development tooling and extensibility.  Sharepoint can now give and receive data from any number of sources.  Want to expose your SQL Server data as a sharepoint list?  No problem.  Want to use your Sharepoint documents as data sources in your .NET application?  No problem.  Need a restful interface to view your Sharepoint data?  No Problem.  Integration isn’t limited to data however, as they demonstrated Silverlight UI’s sitting in front of Sharepoint.  Apparently you can even host sharepoint in the cloud (although that might be a session for tomorrow).

Point #2) If you ever have to make an hour-long presentation of highly technical data, it might be wise not to drink a six-pack of red bull immediately before hand.  The  presenter was so wired, and went so quickly, that even when I wasn’t getting creeped out by him, I didn’t have time to internalize the words coming out of his mouth.  I think at one point he shouted out “I Am Cornholio!” but maybe I just thought I heard that.

EF 4.0 and Beyond (or as I like to call it, Entity Framework 4: STFU)

The theme of the session seemed to be “We introduced Entity Framework, you all said it sucked.  We asked what we needed to do to make it not suck.  You told us.  We did those things, now you need to stop telling us it sucks.”  Adversarial?  Yeah, but hey, at least we’re getting a better product out of it.  They demoed Entity First Design, Support for automatic lazy loading, template generation using T4,  POCO support, offlined objects with dirty tracking, improved control over saving entities and eventing, and FK references.  They also previewed a code only EF model, that generated a data context without a EDMX file, and provided a strongly typed API for controlling model and context behaviors.

 

Connecting applications with the BizTalk enterprise service bus

The first session of PDC 2009 that I walked out of.  Not because the session didn’t sound interesting, or because the featured product was bad.  The presentation was divided between two presenters; the first presenter spoke to the architecture of the service bus and the extensions and providers of the Biztalk ESB toolkit. So far, so good. The problem was the second presenter.  He was so poor he alienated most of the attendees.  Multiple people left the session soon after he began to speak.  It sounded as if he hadn’t planned out his presentation, and his accent made it impossible to discern anything useful.  At one point I think he said something about a Zebra.  I’m not kidding.  For a $2,000 registration fee, Microsoft should ensure their presenters know how to present.   I joined the parade of fellow developers making an early exit.

Partner Expo Reception

The evening’s social event featured an open bar, tasty eats in the vendor expo.  Good Food, Cheap SWAG, and all the technical jargon I could grok.  Geek-On, Baby!


Thursday, November 05, 2009 #

Looks like I’m heading to LA.  I’m really excited to be attending the PDC this year.  I went to the PDC in 03 (where they announced WCF, WF, WPF) and it turned my brain to mush by the middle of day two.  ANyone else going?  Anyone like to share a RSVP promo code to save me some $$$?  I’ll buy you a drink or two!

 

Hope to see you all there!


Friday, October 30, 2009 #

I’ve been spending a lot of time lately debugging through some web-hosted applications.  Some of these applications are hosted by Visual Studio’s own internal web server (Cassini), and others are hosted by my local instance of IIS.

 

Web projects hosted locally get automatic attached to the VS debugger when you press F5.  Projects hosted under IIS do not.  In order to debug IIS hosted projects, you must attach the Visual Studio debugger to the IIS worker process (aspnet_wp.exe or w3wp.exe) manually. 

 

Traditionally, you attach by selecting Attach To Process from the Debug menu, scrolling the list of processes until you find the worker process and then clicking “Attach”.

 

Thanks to this handy macro I found by HologramX at snipplr.com, I’m able to attach with a single keystroke:

To add this macro to your environment,  Tools > Macro IDE > Add new item to MyMacros > Select Module, Name 'AttachToWebServer' > Copy/paste code.

Imports System
Imports EnvDTE80
Imports System.Diagnostics

Public Module AttachToWebServer

Public Sub AttachToWebServer()

Dim AspNetWp As String = "aspnet_wp.exe"
Dim W3WP As String = "w3wp.exe"

If Not (AttachToProcess(AspNetWp)) Then
If Not AttachToProcess(W3WP) Then
System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
End If
End If

End Sub

Public Function AttachToProcess(ByVal ProcessName As String) As Boolean

Dim Processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
Dim Process As EnvDTE.Process
Dim ProcessFound As Boolean = False

For Each Process In Processes
If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = ProcessName) Then
Process.Attach()
ProcessFound = True
End If
Next

AttachToProcess = ProcessFound

End Function

End Module

 

To set as a keyboard shortcut go to Tools > Options > Keyboard, and search for the name of the macro (AttachToWebServer) and then assign a keyboard shortcut.

IIS-Attached Debugging is now one keystroke away.


Monday, October 19, 2009 #

When adding an item to a dictionary, I always thought you had to use the Add() method, like this:

string key = "MyKey";
int value = 20;
var myDictionary = new Dictionary<string, int>();
myDictionary.Add(key, value);

Apparently, you can directly reference it in the collection, and if the key doesn’t exist, its auto-added to the collection

string key = "MyKey";
int value = 20;
var myDictionary = new Dictionary<string, int>();
myDictionary[key] = value;

most likely you already knew this.  I did not.  Its the little things I guess.