Problems with MSBUILD tasks after playing with Visual Studio 2010

I use a custom MSBUILD xml file to build some of my projects so that i can run stuff to compress CSS/JS files and stuff like that. After installing Visual Studio 2010 and playing around a bit with suddenly my builds started to fail.

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(132,11):
error MSB4064: The "Retries" parameter is not supported by the "Copy" task. Verify the parameter exists on the task, and it is a settable public instance property.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(130,5):
error MSB4063: The "Copy" task could not be initialized with its input parameters.

After some debugging i realized that Visual Studio 2010 had changed a line in the csproj file of my web application project.

From:

To:

I just had to change this line back to v9.0 to get it to work again. Hopefully this can help someone that has the same problem as me.

Send “fake” e-mails with smtp4dev

I have always thought it has been a hustle to send e-mail from my localhost. As the spam problem has been more and more serious it has been harder and harder to send mails. But today i found this beautiful little app that act as a fake SMTP server. Just use localhost as your smtp server and all mails sent from your application locally will be displayed in its little UI.

2009-12-07_1610

Link: smtp4dev

Alternatives to ReSharper

I like the tool ReSharper but i do not really have the money to pay for it. My own site AlternativeTo has some list of alternatives but it would be great if we could add some more.

Ps. This is more or less a test post to test some new functionality on AlternativeTo.

Great tools to test JSON and (totally unrelated) Pingbacks

I’ve done lot’s of “web 2.0″ stuff lately and i just want to write down to really nice tools i found.

Test and Validate JSON

I have just built an API for AlternativeTo. It use JSON and this tool was really a life saver when it came to debug and test everything.

http://jsonformatter.curiousconcept.com/

Test if you website handles Pingbacks correctly

Right now i am implementing a pingback functionality on AlternativeTo and i found this little website that lets you sent pingbacks without having to create a new Wordpress post each time you want to test if everything works. Great stuff.

http://www.solitude.dk/ping/client.php

Return random rows from a MS SQL database

I always forget this command:

SELECT * FROM YourTable TABLESAMPLE SYSTEM (10 PERCENT)

This gives you some sample data from your database. In this case 10 percent of the content.  You could also use TABLESAMPLE SYSTEM (1000 ROWS) to get 1000 sample rows. Great to use if you have a big database and do not want the same data again and again when you debug or something.

Convert String Array to Int Array and vice versa in C#

Sometimes you want to convert arrays back and forth. This is to nice extension methods to convert a int array into a string array and vice versa.

public static class ExtensionMethods {

  public static string[] ToStringArray(this int[] intArray) {
   return Array.ConvertAll<int, string>(intArray, delegate(int intParameter) { return intParameter.ToString(); });
  }

  public static int[] ToIntArray(this string[] strArray) {
   return Array.ConvertAll<string, int>(strArray, delegate(string intParameter) { return int.Parse(intParameter.ToString()); });
  }
}

Convert all checked checkboxes into an comma seperated string with JQuery

Sometimes i just love jQuery. Well most of the time actually. I did some work for a client a couple of week ago and i needed get all checkoboxes that was checked as a comma seperated list. I started with this code. I found out about the “map” method of jQuery wich has the following description.

Translate all items in an array to another array of items.

The translation function that is provided to this method is called for each item in the array and is passed two arguments: The the item to be translated, and index within the array.The function can then return the translated value, ‘null’ (to remove the item), or an array of values – which will be flattened into the full array.

The code i ended up with looked like this. Really really neat.






    
    

ASP.NET postback via JQuery / Javascript

ASP.NET Webforms isn’t the best platform to build web applications. I can’t wait to migrate my apps to ASP.NET MVC but until i have the time to do that i have to coup with some of asp.net strange parts.

Today i wanted to invoke a postback via JQuery wich actually was fairly easy but i wanted to write a small post about it.

The trick was to get the Javascript that asp.net call to do a postback, save it somewhere and then executed via the eval() method. I used a hidden form to store the postback script.

In the asp.net file

hdnSearchPostBack.Value = Page.ClientScript.GetPostBackEventReference(SearchButton, string.Empty);

In the js file

function() { eval($("#ctl00_ctl00_hdnSearchPostBack").val()); }

Simple as that!

SQL Server: Saving changes is not permitted because table will be re-created

Microsoft has added a setting to Management Studio to prevent us from re-create tables when we make changes to them. I don’t like this settings and it would have be much better if they said ‘This table will be re-created, are you sure you want to do that?” instead of just stop us from doing it.

There is an option to turn this off if you go to “Tools -> Options -> Designers -> Table and Database Designers” and the uncheck the checkbox “Prevent saving changes that require table re-creation”.

sql_option

Quick attach to process in Visual Studio

When i debug web applications i like to go with the attach to process instead of pressing F5 when i use IIS as the development web server. It has lot of advantages:

  • If you are “deep down” in your application you do not have to start from the beginning again. Attach to process lets you debug the tab/window you already using.
  • When you “press play” in VS and have Firefox as the default search engine you Visual Studio opens a new tab each time you start and you end up with X number of tabs with your app.
  • Probably more that i can’t think of right now.

Anyway the big disadvantage with this is that it is a pretty tedious process to attach to a process.

  • Press ctrl-alt-p to bring up the attach to process dialog.
  • Scroll down to w3wp.exe and “attach” it. For some reason it doesn’t work to press “w” here either so you have to scroll down manually.
  • Click ok and then you have to confirm that you really have to do it.

I have been doing this for months but today i decided to see if Google had any answer to my problem and surely it did. I found this question on Stackoverflow. The answer to the question was to record a macro in Visual Studio that do this for you.

  • Press ctrl-shift-r to start record the Macro.
  • Do the steps i described above to attach to the process.
  • Press ctrl-shift-r again to stop the recording.

Now you have the attach to process as a temporary macro and can run it with ctrl-shift-p. You will get an error if you try to run it when you already attach to a process and so on but it work. If you want to you can look for the error 0×8971001E and add DTE.Debugger.Stop(True) in the catch part of the macro.

You can also save the macro and add it to your toolbar, attach your own keyboard shortcut to it and so on. Check out this article about macros on “Switch on the code”.