Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Tuesday, February 11, 2014

Formatting all files in a solution in Visual Studio

When I had to format all files in a solution,
all I could find at first were macros. Since Visual Studio 2012 doesn't have the macro explorer anymore,
I had to find an other way to accomplish this.

Thanks to this github page I found the follow code that accomplishes just what I need.
Open the Nuget package manager console and paste in (2 lines) :

function f($projectItems) { $projectItems | ? { $_.Name.EndsWith( ".cs" ) } | % { $win = $_.Open('{7651A701-06E5-11D1-8EBD-00A0C90F26EA}') ; $win.Activate() ; $DTE.ExecuteCommand('Edit.FormatDocument') } ; if ($projectItems) { $projectItems | % { f($_.projectItems) } } }

$dte.Solution.Projects | % { f($_.ProjectItems) }
Thanks JayBazuzi!

Wednesday, February 27, 2013

Visual studio locking files on build

More and more I got a problem with visual studio blocking files on build, (Could not copy dll from debug to bin) mostly in web projects (MVC).
A solution was to clean the solution (getting the same error),
waiting a few seconds, cleaning again,
and then building.
Now I found a solution that seems to work,
right click the project,
properties,
Build steps,
and add to the pre build command line :
if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

(You need to copy the double quotes too).
It might be needed to add this to more than one project in your solution, just look at the error you get when building.

Thursday, December 18, 2008

Linq Where not exists query

Today I needed a where not exists query in my linq to objects.

Fortunatly I found it using the google :)

Suppose we have 2 lists, the first of a dummy class with properties Id and Name, the second of another dummy class with properties Id and Color (just so they are different)

We can perform a 'where not exists' query as follows :

var OnlyInFirstQuery = (from item1 in list1 select item1.Id)
.Except
(from item2 in list2 join list1Item in list1 on list2.Id equals list1Item.Id select item2.Id);


This will give us a list having only the items in list1 that do not exist in list2, just as I needed.

Tuesday, August 26, 2008

Linq To SQL Stored Procedure returns an Int

Today I was using Linq To Sql to execute a stored procedure wicht returned results by using a temporary table and dynamic sql (not my stored procedure)
Suprisingly enough when I dropped the procedure on the dbml file,
it generated a function with the return value typed as integer.
As it turned out, linq to sql and temporary tables don't play nice.
And since the database was a sql 2000 db, using table variables was not possible.

The solution turned out to be simple enough,
replace the stored procedure with a dummy one that returns the fields your normal procedure will return (names and type).
Then drop this stored procedure on the dbml file.
This will generate the correct return type for your procedure,
then simple alter the stored procedure to the correct one.

Hurrah, we can now use linq to sql to use our difficult stored procedure.

Thursday, May 15, 2008

Visual studio 2005 toolbox icons messed up.

When I started VS 2005 today I noticed all my icons where messed up :



This makes finding the right control a little harder.

The solution is quite simple : Right click the toolbox and choose reset toolbox,
and presto , icons back.  Unfortunatly this also removes any custom items and tabs in the toolbox.

I also read that deleting all tlb files in  C:\Documents and Settings\_username_\Local Settings\Application Data\Microsoft\VisualStudio\8.0 can work, but did not try it myself.
I don't know what other things might be removed when you delete these files, so be carefull!

 

Wednesday, May 7, 2008

Problem adding files to deployment project

For some time now I have had problems adding files to the file system editor portion of a deployment project.

When I right clicked, add file, browse for a file, any file (dll / jpg / xml / txt / ...)
It would not add this file to the project,

Luckily there are workarounds for this issue (no definite fix found yet) :
- the simplest is just closing and reopening visual studio
- Rebooting your pc may also work
- Adding a shortcut to the file (which will add the file also), and deleting the shortcut (I have not tried this yet myself)
- Resetting your visual studio settings can also help (also haven't tried this myself)
- Some even say that reinstalling fixes this problem (which will ofcourse open & close visual studio and reset the settings ;-) )

Thursday, February 14, 2008

Connecting to an Access Database in Visual Studio 2008 Server Explorer

Trying to connect to an MS Access DB from the visual studio 2008 Server Explorer gave me a little surprise to see that the window I got to create the connection only gave me the possibility to type in the connectionstring myself.

Trying several possibilities, the test connection button always cleamed the connection was OK, but when clicking OK i received the following message :

format of the initialization string does not conform to specification starting at index 0
After a long search, the solution was found, something is incorrect in the registry :
- Open the registry using regedit
- Find the  "HKEY_CLASSES_ROOT\CLSID\{F9AE8980-7E52-11d0-8964-00C04FD611D7}"  in the tree
- Check if there is a subkey named ProgID there, if there is, you are not having the same problem as I had, but be sure to check the value

If the key is not there, add it :
- Right click the node and click new, key
- Name it ProgID
- Select the newly created key
- In the main (right) pane, doubleclick the "(Default)" value
- Set its value to "MSIDXS.1" (without the quotes ofcourse).

Now when you create a new connection to an access DB, you can use the correct window.

Wednesday, December 12, 2007

Microsoft has released Volta

About a week ago Microsoft released Volta from the labs.


What is Volta :


Volta is a developer toolset for building multi-tier web applications using existing and familiar tools, techniques and patterns, It allows to make the decisions until the very last passible moment.

It also enables new end-to-end profiling and testing.

It makes that you can build your application as a .NET client application and then assign parts of your application to the client side or the server side. The compiler automatically creates cross-browser JavaScript, web services and all required code for the tiers to communicate.


Volta has the following advantages :
In the architectural dimension :

Language-independence. Write Volta code in any language that compiles into MSIL. For example, C#, VB, IronPython, etc.
Leverage the entire .NET toolchain. Use libraries; the IDE, Intellisense, auto-complete, snippets; FxCop; profiler; class browser; ILDASM; and so on.
Low entry barrier. Reduce your learning burden; use “only the languages in the room.”
Brown-field applicability. Volta-enable existing applications for the cloud.
Beyond 2 tiers. Refactor to as many tiers as you need using exactly the same mechanisms recursively applied.

In the execution-platform dimension :
Deep embedding of CLR semantics. Preserve exact CLR semantics across platforms.
Cross-browser support. Use one programming model across browsers.
Complete orthogonality with refactoring. Mix and match refactoring and retargeting.
Ajax-ready. Write Ajax patterns and idioms in familiar .NET languages.
Debugging transparency. Debug code with a specific browser.
Leverage browser-specific features. Where needed, access features unique to each browser.
Visual-Studio integration. Enjoy seamless integration with the IDE.


In the next post we will make our first Volta application.
Can't wait?
Download volta here : http://labs.live.com/volta/download/

Friday, September 21, 2007

LoadTest troubles

After installing a loadtest Controller and an agent using the Visual Studio 2008 Beta 2

the controller indicated that the agent remained disconnected, 
after searching i found out that the user did not belong to the TeamTestAgentService user group on the controller, after adding this user the agent become ready.

another usefull utility is the AgentConfigUtil.exe tool.

You can also check the log files  for errors :   \LoadTest\agentConfigUtilSetup*.log file for errors.

Another possible error sis : “Rig failed to restart for controller . The following error was reported Cannot open VSTTController service on computer .”

This error occurs when the when the user tries to restart the rig from the Administer Test Controller dialog box, but the user doesn't belong to the Power User or Administrator group.

More info for loadtests :
Ed Glas's blog

Friday, March 23, 2007

Access the clipboard from a visual studio macro

Visual Studio macros can save a lot of time,
automating the workspace,
but when you try to access the clipboard,
the following error pops up :
Current thread must be set to singe threat apartment (STA) mode before OLE calls can be made. Ensure that your main function has STAThreatAttribute marked on it.
Not so nice,

The trick to solve this is create a new thread, have the STA flag set and let that thread access the clipboard.

I created a new macro module modClipboard with the following functions :

Private clipText As String

Public Property ClipboardText() As String
Get
RunThread(AddressOf GetClipboardText)
Return clipText
End Get
Set(ByVal value As String)
clipText = value
RunThread(AddressOf CopyToClipboard)
End Set
End Property

Private Function RunThread(ByVal fct As Threading.ThreadStart)
Dim thread As New Threading.Thread(fct)
thread.ApartmentState = Threading.ApartmentState.STA

thread.Start()
thread.Join()
End Function

Private Sub GetClipboardText()
clipText = Clipboard.GetText()
End Sub

Private Sub CopyToClipboard()
'The second parameter is required
Clipboard.SetDataObject(clipText, True)
End Sub

The module variable (cliptext) is required to transfer the data between the threads.

And now we can call the property in our other functions :
 
Copy to clipboard :
ClipboardText = "Whatever you want"

Get the clipboard data :
  strClipboard = ClipboardText