English 中文(简体)
Using the nupack Package Manager Console to set working folder to solution folder
原标题:

In Visual Studio, nupack adds a power-shell window called the Package Manager Console. I am thinking that this would be a good place to run source control commands (I m using Mercurial). However, the default working directory is my users folder, so I need to navigate to my code folder every time I load a new project.

I am wondering if there is a one-line command to set the working directory to the solution folder. e.g. does something like this exist?

cd $SolutionFolder

From the results of get-variable it doens t look like there is anything immediately available, but I ve never used powershell before, so maybe there is a way of getting the solution folder?

最佳回答

Thanks to Doug for pointing me in the right direction. I ve written up full instructions on my blog here:

http://mark-dot-net.blogspot.com/2010/10/change-to-solution-folder-in-package.html

The basic answer is that the following command will do it:

Split-Path -parent $dte.Solution.FileName | cd

To make it more readily available, you need to create a function in your "user profile" script file, the location of which is found in the $profile variable. You will need to create the file if it doesn t exist. Then add a function:

Function solutionFolder()
{
    Split-Path -parent $dte.Solution.FileName | cd
} 

Now, after loading a solution in VS2010, you can simply type:

solutionFolder

and the working folder will be changed.

问题回答

Try

$dte.Solution.FileName

I m not sure when it changed, but the Package Manager Console automatically shifts the working directory to the current solution folder when you open an application now.





相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签