How to set the working directory for MS Test projects - visual-studio-2012

how can I set the working directory for MS Tests projects, like I can do it for normal application projects? My Component that is tested need to access some config files that are also used by other applications. So far I have to copy these files the bin/debug folder of my test project, as these files are expected to be in the working directory.
Is it possible to set a working directory for test projects?

For those who use Visual Studio 2012, if you set the output directory of the test project under Properties|Build|OutputPath then that will become the working directory when you run the tests from Visual Studio (since it is using Vstest.console.exe). If you don't want to have your test dlls, etc output to the same directory as your other files and you don't want to have the other files as content in your test project (as suggested by Schaliasos) then you can set the path on startup in a method that has the [AssemblyInitialize] attribute. You do this by assigning System.Environment.CurrentDirectory as usual. You will probably want to have the working directory as a setting or read from a configuration file.
Edit
As pointed out by Rohit.Net, when you choose Run All Tests the default path would be under TestResults. The same applies when using a runsettings file. The output folder will be the default working directory when you are not using DeploymentItems and: -
You right click the test(s) in Visual Studio and choose to run / debug, or
You run from the command line using vstest.console.exe.

The working directory for test projects is created at the time you start running your tests.
If you run them locally this is created in a folder TestResults inside your project folder. If you run them in remote machines a different folder is created in each test agent in the following path:
C:\Users{userRunsTheTest}\AppData\Local\VSEQT\QTAgent\{GuidForThisRun}
In order your files to be deployed in these folder and have access to them you have to:
Set the Copy to Output Directory = Copy Always
In the test that needs these files set them as DeploymentItems.

Acarlon's suggestion does not work when you select Run All tests from Test Explorer in Visual Studio 2012.
The default path you would get is something like ...\TestResults\Deploy_<YourName>2014-01-13 14_48_20\Out folder.
Because of this there may be possibility that your DB would not be accessible when entity would try to open connection for running entity related Test.
In my case I am using SQL CE which is set as resource file and always compiled and gets itself dropped into the Bin/Debug/Resource folder.

Related

How to set RubyMine's default working directory to the executing .rb program's subdirectory?

In RubyMine, I have a project with many subfolders, each of which contains:
One or more standalone single-file executable Ruby programs (.rb files);
An input text file.
In older versions of RubyMine, when running one of the standalone executable programs (via Cmd+Shift+R on my Mac), the default folder in which RubyMine would look for the input file would be the same directory as the .rb file currently being executed -- which worked great.
The code used to read the file is something like:
data = File.readlines('input.txt')
However, after recently updating RubyMine to v2022.3.1, the behavior has changed, such that RubyMines now seems to be looking in the project's root directory for the file, instead of the same subdirectory as the .rb file currently being run. This produces the error:
in `readlines': No such file or directory # rb_sysopen - input.txt (Errno::ENOENT)
To correct this, I've been going into Run (menu) > Edit Configurations; and in the Edit Configurations dialog, in the configuration that RubyMine auto-created for the current executable file, changing the Working Directory value from the default of the project's root directory, to the subfolder of the current .rb file.
However, this above workaround is annoying, since I need to do it once each for every individual one of the many individual .rb executable files in my project.
My question: How can I configure my project and/or RubyMine itself to go back to the older behavior of defaulting a given .rb file to use its own directory as the default Working Directory, instead of the project's root directory?
(This question and/or its solution might also apply to other JetBrains IDEs such as IntelliJ, since they all seem to work similarly.)
The previous behaviour has been changed with https://youtrack.jetbrains.com/issue/RUBY-29236. So now yes, the logic is the following:
in case of no Ruby module, project's root will be used
in case of Rails, its home folder
otherwise the module's root
There is no option to change it in RubyMine but you can configure the configuration template using some variable there as Working directory.

how to move workspace(a simple project) from windows file system (/mnt/) to linux (~/home)

I am developing a Django project (nothing) and trying to use using WSL2.
so if I use the Ubuntu Terminal from Windows to create a project and try running it in VScode, I got this little message,
I just don't know how to do that at all,
it's the first time I tried to use WSL2 (which is awesome), if someone could help, thank you very much.
If you have your project in some mounted folder -> linux path starting with /mnt/ e.g.
/mnt/c/Users/rasto/Desktop/some_folder/my_project/
When you open VS Code in this directory (via running command code . or opening the VS Code from windows) you get the warning:
This workspace is on the Windows file system (/mnt/). For best performance, we recommend moving the workspace to the Linux file system (~/home).
The solution is easy -> move/copy the project folder to ~/my_project/ directory:
In WSL terminal:
Recursively copy all files from source-path to destination-path and if the folder ~/my_project/ does not exists, it will be created
cp -R /mnt/c/Users/rasto/Desktop/some_folder/my_project/ ~/my_project
Move to the directory in your terminal
cd ~/my_project
And open VS Code from console with
code .
Note: To open VS Code from terminal you must have installe extension Remote Development extension pack
Note2: To access the linux folder from windows file explorer just right click in VS Code explorer and Reveal in explorer or with the path like: \\wsl$\Ubuntu-18.04\home\rasto\my_projects

How can I get Unit Tests to run against the appropriate DLL when the DLL cannot be referenced in the project?

I've got the following "Pre Build Event" working for my powershell builds (including our Continuous Integration). It simply moves a DLL into the output directory based on the Processor Architecture.
if '$(PROCESSOR_ARCHITECTURE)'=='AMD64' (copy /y "$(ProjectDir)x64\sqlite3.dll" "$(OutDir)")
if '$(PROCESSOR_ARCHITECTURE)'=='x86' (copy /y "$(ProjectDir)x86\sqlite3.dll" "$(OutDir)")
if '$(PROCESSOR_ARCHITEW6432)'=='AMD64' (copy /y "$(ProjectDir)x64\sqlite3.dll" "$(OutDir)")
The problem I'm running into is when I run the Resharper Unit Tests within the IDE. When I do this, the Pre Build event doesn't run, and therefore all of the tests that depend on the sqlite3.dll fail.
What I need to do is either be able to move the appropriate file into the output directory before the Test Runner runs, OR make sure the Test Runner runs against ONLY the x86 Architecture, whereby I can just drop the appropriate file in the bin\debug folder and be done with it.
Things I've tried:
I've tried setting the "Build Settings" to "Always Build" but this has no affect on the outcome. It appears as though the build in the IDE doesn't run the Pre Build Event
I've also tried to set the default platform architecture in [Resharper -> Options -> Tools -> Unit Testing] - as per the docs, but unfortunately my version of R# doesn't have that option (7.1.3)
You can force the C# project to be 32 bit only, and the ReSharper runner will only run it as 32 bit. That way, you can drop the x86 dll in the bin\debug folder and it should all just work.

InstallShield - adding configurations to file

I'm building a setup project by using InstallShield. The setup file will do the following tasks:
Install my application to the machine.
Look for a folder based on a common string (e.g: MySecondApp) because each machine might has different folder name:
Laptop1: C:\Program Files\WindowsApp\MySecondApp_1.2.3.4_asdfsjhewrnewj
Desktop2: C:\Program Files\WindowsApp\MySecondApp_1.2.3.5_asdfsjhewrnewj
In this folder, I have a config file named "myconfig.cfg". My setup file will modify this file by adding some new configurations.
Could you let me know how to do this by using InstalledShield?
Thank you very much
I've resolved this problem by writing a C# library and use it in InstallShield for searching and modifying my config file.

Where's the "TEMP" folder for Custom Build Steps?

Visual Studio 2010, in my project I made a custom build step which renames a dll file and copies it to other folder. So, Alt+F7, Config props, Custom Build Step / General, command line:
copy /y $(TargetPath) $(TargetName).node
It didn't do anything. Then I also added
ping bat.femei.ro -n 1 -w 5000
It still didn't do anything. It simply flashed a command prompt window for a split second then the window went away. I googled as much as I could concluding that there might be a problem with the folder where the batch file is generated.
I did my best to screenshot that split second with the command prompt and after a boring F7-PrintScreen-PasteInPaint session finally I got
C:\Users\FURAT\AppData\Local\Temp\blablablablablablablablabla.exec.cmd is not recognized as internal or external...
I double checked the directory. It has Everyone permissions set to Allow both Read & Write operations. What's wrong? How do I fix this?
I was unable to find any knobs to tweak temp folder path. It's not Env and it's not in the config either.
What did work however was running VS2010 as Administrator. Now the Custom Build Step works.

Resources