4

We use fluentmigrator and it wants a long for the migration number.

Normally I can just open the immedetiate window and type

System.DateTime.Now.ToString("yyyMMddhhmmss");

But sometimes it will say:

The expression cannot be evaluated while in design mode.

So I start debugging run the command again and get this error:

The expression cannot be evaluated while in run mode.

Edited to add

If I start debugging and hit pause and enter the command I get

Cannot evaluate expression because the current thread is in a sleep, wait, or join

If I start debugging hit a break point then it works but that is too many hoops to jump through and it has worked in the first scenario. It seems to build my project since if there were errors it wouldn't execute.

This is in visual studio 2010 pro.

Bonus points if one can tell me how to do this as a class template or maybe a powershell type thing?

I've tried the answer in Immediate Window, "The expression cannot be evaluated...." and selecting the project doesn't work. I don't get the > in the immediate window and if i put it before the command i get

Command "..." is not valid.

Edited To Add I created this gist to do what I wanted.

https://gist.github.com/9ad816c2b8e56b57ef79

basically a powershell command to create a c# template with some crap filled in.

Community
  • 1
  • 1
Steve
  • 25,806
  • 2
  • 33
  • 43
  • Read about [func-eval](http://blogs.msdn.com/b/jmstall/archive/2005/11/15/funceval-rules.aspx) to see how this is extremely complicated. – SLaks Feb 29 '12 at 00:06

3 Answers3

3

Why not just use PowerShell:

PS> [DateTime]::Now.ToString("yyyMMddhhmmss");
20120228043351
Scott Hanselman
  • 17,712
  • 6
  • 74
  • 89
2

I'm not a visual studio user but this is how you can get the value with a PowerShell cmdlet:

Get-Date -Format yyyMMddhhmmss
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
1

You need to execute it in the third mode – Debug mode (paused in the debugger).

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • my configuration is set to Debug if that is what you were meaning? – Steve Feb 28 '12 at 23:58
  • 1
    No; I mean you need to pause execution in the debugger, using a breakpoint or the Pause button. – SLaks Feb 28 '12 at 23:59
  • It sounds like the OP is executing this from the immediate window while not debugging. In that scenario Debug vs. Release vs any other mode shouldn't have an effect on an expression like this (doesn't depend on any application statics). – JaredPar Feb 28 '12 at 23:59
  • @JaredPar: I don't mean configuration. – SLaks Feb 29 '12 at 00:01
  • @SLaks ok. But that wouldn't address the first error the OP hit – JaredPar Feb 29 '12 at 00:03
  • @SLaks i get Cannot evaluate expression because the current thread is in a sleep, wait, or join if I do that. – Steve Feb 29 '12 at 00:04
  • @Steve: You need to use a breakpoint to pause the debugger inside your code. – SLaks Feb 29 '12 at 00:05
  • @SLaks I'm not trying to debug any specific code per say, I just need to generate a long for the migration. If I have to start debugging pause on a breakpoint then execute the code in the immed window I might as well just put this command in the code temporarily to see what the value is. That's too much work and why I used the immed window in the first place – Steve Feb 29 '12 at 00:08
  • @Steve: The Immediate Window cannot work at runtime unless you're in a specific location. See http://blogs.msdn.com/b/jmstall/archive/2005/11/15/funceval-rules.aspx – SLaks Feb 29 '12 at 00:09