I successfully installed Visual Studio 2019 for Mac (community edition, version 8.10.14) and managed to install few other required extensions/packages for my work. These are Specflow, Specflow.NUnit, Selenium WebDriver & Server.
I added one feature file and unable to create step def for that feature file as there is no option i can see to create step def. I try and added a separate file (template is called 'specflow step definition' from right click on folder then add>new file) and it's like added sample step def for calculator sample feature. When i right click on steps in feature file it doesn't show an option to generate step defs.
This issue is only on Mac OS. The same project works perfectly fine on windows machine.
A cursory search for specflow visual studio mac seems to conclude that this is not yet available for MacOS versions of Visual Studio. On Windows, the SpecFlow extension for Visual Studio allows you to auto generate step definitions from a feature file. This does not appear to be supported on MacOs, but there is a feature request to add support.
In the meantime, stubbing out a step definition class isn't too bad. The basic shell is:
using TechTalk.SpecFlow;
[Binding]
public sealed class YourStepDefinitions
{
[Given(#"...")]
public void GivenX(...)
{
ScenarioContext.Current.Pending();
}
[When(#"...")]
public void WhenX(...)
{
ScenarioContext.Current.Pending();
}
[Then(#"...")]
public void ThenX(...)
{
ScenarioContext.Current.Pending();
}
}
The challenge is getting the regular expression right. Unfortunately, that requires knowing the step before creating the step definition.
See Step Definitions for more information.
Related
I'm trying to develop a VS extension using the Visual Adornment project template.
The extension is working on the experimental instance of VS (it simply adds a text layer on the editor window), but now I'm trying to add 2 features, with no luck:
Help/About entry for the extension
Settings page for some basic configurations
So I started to study some other extension to understand how they do that, taking as example this from Phil Haack Encourage.
No way I can get it to work. I created a class that inherits from Microsoft.VisualStudio.Shell.Package and I've decorated it with all the needed attribute to have the Help/About entry, without any success.
[PackageRegistration(UseManagedResourcesOnly = true)]
[ComVisible(true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid("665d2c8c-0d47-42b6-ae34-e1db4ac2ed0f")]
public sealed class MyPackage : Package
{
public MyPackage()
{
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
}
protected override void Initialize()
{
base.Initialize();
Debug.WriteLine("Initialize MyPackage");
}
}
Not only the package is not registering, but the debug lines are not written at all, I cannot even step in with the debugger.
I took a look around the web, and any article I found sounds like this one, even following any single step, my package is not registering itself BUT, and it is the strange thing, the viewport adornment it's working as expected...
UPDATE:
I can add some details: it seems that during the build the .pkgdef file is not created at all in the debug folder, and it's not added to the VSIX file (if I open it with 7zip there's no .pkgdef)
No way I can get it to work. I created a class that inherits from Microsoft.VisualStudio.Shell.Package and I've decorated it with all the needed attribute to have the Help/About entry, without any success.
I didn't understand that part quite. You're supposed to use Visual Studio "project template" for "Visual Studio packages". That will create all the stuff necessary to build VSIX file. Start with that, if you already haven't.
By default, Visual Studio extensions(>=2013) don't load automatically. This took me few hours of debugging, but you're supposed to decorate your package with an attribute if you'd like to load when Visual Studio starts up. Alternatively, there's an option to load your VSPackage once a solution is loaded.
This is a peek of my package definition:
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(Guids.GuidMyStudioPackageString)]
[ProvideAutoLoad(UIContextGuids.NoSolution)]
[ProvideMenuResource("Menus.ctmenu", 1)]
public sealed class MyPackage : CommonPackage
Notice the [ProvideAutoLoad(...)] option. It says that load the package once visual studio starts.
In an existing solution I added a new Test Project. In my Test Project .cs file I have a class decorated with the [TestClass] attribute and a method decorated with the [TestMethod] attribute. I have verified that in Configuration Manager the build check box is checked for the Test Project (as my google search has revealed was the problem for others with this issue). I have set Test Project as my start up project for the solution. When I try to start the test I get "Can not start test project because the project does not contain any tests". I am really new to unit testing. What am I missing?
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Whole bunch of stuff
Assert.Inconclusive("Done");
}
}
Update: So I opened a new instance of VS, went to File => New => Project => Test Project. Did not touch or edit anything. Went straight to the cs file and here are its contents in its entirety:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject2
{
public class Inspection
{
public bool SubmitInsp()
{
return true;
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Inspection insp = new Inspection();
bool result = insp.SubmitInsp();
Assert.IsTrue(result);
}
}
}
Same error about the project not containing any test when I try to start it. Also found this in the build output "Could not load file or assembly '~\my documents\visual studio 2010\Projects\TestProject2\bin\Debug\TestProject2.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
I don't know that units tests get much simpler than this. What the heck???
I've had the same problem, when tests in an working test project suddenly weren't recognized anymore.
Comparing the project file with one from another working test project showed me that the <ProjectTypeGuids> node was missing from the main <PropertyGroup> node.
Adding this line inside the <PropertyGroup> node solved my problem:
C#:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
VB:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
I was able to get this to work by modifying the devenv.exe configuration file found here:
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config.
Add the following line to the <runtime> section, then restart Visual Studio:
<loadFromRemoteSources enabled = "true" />
(Here is the link that helped me)
The FrstCBC's anwser did not worked for me.
I am on a VirtualBox machine with Windows 7 64 bits and Visual Studio 2012.
I had to move the output to a local folder : open the unit tests project properties and in the Build tab, browse the Output path to a local folder. The tests are now detected and can be run.
Test Projects saved to a network folder or anywhere locally on my computer have this issue. Created another Test Project and saved it to my flash drive, works just fine. I don't know if it is because my machine is 64 bit or because its a virtual machine or what, but I guess I just need to test everything on external storage devices.
For me it was just that my class and method weren't public (I realize the poster did have public, but I found this post by Googling "testclass testmethod margin icons missing"). Dumb mistake on my part, but maybe it will help others.
Verify that all the .cs files are marked as Compile in the Properties window. If it is marked as Content then you will hit this issue.
I am trying to do the quick start example, I bring in the ref's using NuGet in VS2010, I scrape the sample code on the webpage, I see my NUnit Session window, I click the green arrow, but the browser doesn't get invoked (doesn't start). What am I missing?
using System;
using NUnit.Framework;
using WatiN.Core;
namespace FirstWatinProject
{
[TestFixture]
public class Class1
{
[Test]
[STAThread]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnK")).Click();
Assert.IsTrue(browser.ContainsText("WatiN"));
}
}
}
}
I am getting the following error in NUnit Sessions window;
SearchForWaitOnGoogle Failed: System.IO.FileNotFoundException: Could
not load file or assembly 'Interop.SHDocVw, Version=1.1.0.0,
Culture=neutral etc...
Okay, solved the error, it is as the following other overflow thread concludes;
WatiN System.IO.FileNotFoundException Interop.SHDocVw
BUT, a key action in the sequence is to build the class library project AFTER setting the Interop.SHDocVw dlls' 'Embed Interop Types' property to 'False';
Then you can hit the green arrow in NUNIT Sessions window and you will see the IE browser startup after a second or two. Simply click it and you will see whatever actions you have programmed.
God is in the details!
Setting the Interop.SHDocVw, Microsoft.mshtml dlls' 'Embed Interop Types' property to 'False';
Of course Visual Studio would give you warnings on how to amend.
The Use of Nugget Package Manager
Check for the availability of Interop.SHDocVw.dll,
Make sure that your project has a reference to Interop.SHDocVw.dll and the dll is present in the Bin/Release Folder depending upon how you are running..
Just select Build from the main menu...then select Configuration Manager. In the list select you project and change its Plateform 'Any CPU' etc to x86.
If you have only Only CPU option, you can use ... option when chosing platform and create new setting, that is for X86 platform and then choose it.
ref:
Change target to x86 in VS2010
I already had a reference to Interop.SHDocVw. The easiest fix for me was simply changing .NET from 4.5 to 3.5 in Visual Studio settings. After making the change, it worked fine.
In the past we have used Advanced Installer to build our .msi installers for a particular project. Our yearly license for Advanced Installer has expired, so to avoid the renewal cost, and because I think the same can be accomplished with Visual Studio, I am attempting to use a Visual Studio 2010 Setup Project to build my .msi.
For the most part, the installer I have built with Visual Studio works fine. However, one thing we need the installer to do is run a couple of .reg files to add a large collection of settings to the registry (It may be worth noting that this is old software that is only being maintained and updated until it is replaced entirely in the near future. It is not practical to change our method of storing settings). With Advanced Installer, we were able to execute a .cmd file as an "Install" Custom Action that would run these .reg files that were also included in the installation. VS Setup Projects have Custom Actions, but it appears that here they are required to be either .dll or .exe files, so I must find an alternative to using a .bat or .cmd file.
First, I tried adding a Command Line project to my solution that consisted only of the following lines in the main() method:
using (Process registryInput = Process.Start("regedit.exe", "/s Settings1.reg"))
{
registryInput.WaitForExit();
}
using (Process registryInput= Process.Start("regedit.exe", "/s Settings2.reg"))
{
registryInput.WaitForExit();
}
I added the Primary Output of this project to the "Install" folder of the "Custom Actions" editor. Tried to run the installer, but the command line process never seemed to run and no registry settings were installed. If I manually ran the command line executable from the application directory where it was installed, it added the registry entries as intended - so the problem is not with the code I'm using to call the .reg files.
I turned to MSDN and changed my solution to be modeled after their Custom Actions Walkthrough. I created a Class Library project (and removed my Command Line project) and added an Installer Class. Instead of starting up a browser using Microsoft's website URL in the Commit() method as shown in their example, I added the code above to the Install() method. Here is what I ended up with:
[RunInstaller(true)]
public partial class Installer1 : System.Configuration.Install.Installer
{
public Installer1()
{
InitializeComponent();
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
using (Process registryInput = Process.Start("regedit.exe", "/s Settings1.reg"))
{
registryInput.WaitForExit();
}
using (Process registryInput = Process.Start("regedit.exe", "/s Settings2.reg"))
{
registryInput.WaitForExit();
}
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
}
I added the Primary Output of this new Class Library project to the "Install" folder of the "Custom Actions" editor. Still, when I run the installer, the code does not appear to be executed and my registry settings are not added. I have tried this installer both set to "Install for all users" and "This user only".
Any help to either get this Custom Action working or an alternative method to get a .reg file to run on install will be greatly appreciated. Thank you in advance.
I just ran across this same issue, re: the custom action not being picked up by the installer. The resolution was to run Visual Studio as an administrator.
Even though I'm a full admin on my machine without any restrictions (AFAIK), the installer would never pick up the custom actions. As soon as I closed down Visual Studio and then restarted as an administrator (right click > run as administrator), the custom actions were immediately picked up by the installer.
I banged my head on the keyboard for a bit on this one - and only after putting my custom installation actions in the Constructor of the Installer Class made it run.
I followed the tutorial I found here: http://msdn.microsoft.com/en-us/library/d9k65z2d(v=VS.100).aspx
See if this link helps, it helped me:
Visual Studio 2008 Installer, Custom Action. Breakpoint not firing
Basically, code after the
base.Install(stateSaver);
is not getting executed. So put the base.Install(stateSaver); as the last line in the method.
This may seem obvious but it caught me out for a while, so might as well post it.
I was just right-clicking on the installer project and then "Install" and "Uninstall". However, you have to rebuild the Installer project after changing the code! (and probably the project with the installer class as well)
Thanks to StackOverflow I found out yesterday how to add a custom action to the Visual Studio Installer to start my program after an update. The problem I now face is that at the end of the installer the program does open but the installer never finishes until I exit my app.
Is there a way to ensure the app starts only after the user clicks finish on the MSI package?
Or the program starts at finish of installer but installer completes and exits?
I am running Visual Studio 2010 in case it matters.
After some Googling, I found out that the custom action for the Visual Studio Installer might need to point to an Installer Class. So I created a new project of type class in my solution. I deleted the class1.cs file and added an installer class to the new project with the following code (mental note: need to use security.permissions at some point):
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Diagnostics;
using System.Security.Permissions;
namespace AppName
{
[RunInstaller(true)]
public partial class InstallerClass : System.Configuration.Install.Installer
{
public InstallerClass()
{
InitializeComponent();
}
public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
System.Diagnostics.Process.Start(Context.Parameters["TARGETDIR"].ToString() + "application.exe");
// Very important! Removes all those nasty temp files.
base.Dispose();
}
}
}
After the InstallerClass was added, I right clicked on the installer project and selected Add > Project Output and added the installer class. I then right clicked on the installed project and did View > Custom Action. I added the installer class to both the Install and Commit folders (if you only add it to Commit, you will get an Error 1001: could not find file InstallState. because of the override commit, it will only run on commit. apparently InstallState is created at stage 2 so if if its not in both it will fail miserably).
You must add a CustomActionData entry. To do so, select the "Primary Output from InstallerClass" and go to the Properites tab. Paste the following in CustomActionData:
/TARGETDIR="[TARGETDIR]\"
After that was added the app runs properly when the install finishes and you can close the installer instead of waiting on the app to exit!
Just what I needed. Thank you Google for saving my bacon.
The one issue I noticed was the installer now creates multiple .tmp files and a .InstallState file in my ApplicationFolder. I am wondering if there is something in addition that needs to be added to the installer class to get rid of these useless files?
Figured out how to get rid of the temp files. Updated code with Dispose().
I followed the instructions here:
http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx
..And got the "Error 1001: could not find file InstallState" error.
After reading ThaKidd's answer above, I realized that I would have to:
Add the installer class to both the Install and Commit folders.
Really important. Just leaving this here for future visitors (I would have added a comment if SO allowed me to...)
This is a step by step guide to answer the Question and clean up all files on an uninstall Event. I hope this can help people who are new to Visual Studio Installer Projects.
In your solution (.sln) you should have at least 2 projects. One being your program and the other one the setup. Given the Question this guide does not include basics on how to add a setup or the primary output(Here is a video if you need to catch up).
Follow these steps:
Right click on the main project (not the setup) -> Add -> Component -> Installer Class
Name the Component and click Add
Open the file click on switch to code view (or select ComponentName.cs -> ComponentName.Desinger.cs -> ComponentName -> ComponentName())
Take a look at the code below, add the using statements, the commit and uninstall method. Run the code.
Right click on the setup project -> View -> Custom Actions
Right click Install -> Add Custom Actions... -> Application Folder -> Primary Output from yourProject (Active) -> Ok -> Right click the added file and select properties Window (or F4) -> set CustomActionData to /TARGETDIR="[TARGETDIR]\" (one backslash at the end) and make sure that Installer Class is set to True
Repeat the above step for the Custom Actions Commit, Rollback and Uninstall
Rebuild the setup
Install the setup
You may need the System.Configuration.Install NuGet
Full Code
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
namespace Your_Namespace
{
[RunInstaller(true)]
public partial class ComponentName : System.Configuration.Install.Installer
{
public ComponentName()
{
InitializeComponent();
}
//Source: https://stackoverflow.com/questions/3172406/create-custom-action-to-start-application-and-exit-installer
public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
System.Diagnostics.Process.Start(Context.Parameters["TARGETDIR"].ToString() + "your main program.exe");
//Remove temp files
base.Dispose();
}
//Delete the file .InstallState (created when using custom actions in setup)
//Could also delete this after the install (protected override void onAfterInstall) but not tested
//Source: https://stackoverflow.com/questions/46786297/visual-studio-setup-project-remove-files-created-at-runtime-when-uninstall?rq=1
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
File.Delete(Context.Parameters["TARGETDIR"].ToString() + "your main program.InstallState");
//Remove temp files
base.Dispose();
}
}
}
Additional stuff for a Visual Studio Installer Projects (2017, 2019) that might save you a headache later:
Move the default installation from [ProgramFilesFolder] to [LocalAppDataFolder] so you don't have to ask for admin privileges every time a file is modified (View -> File System -> Properties of Application Folder -> Default location)
Shortcuts are missing the full context menu
Update removing some files especially shortcuts
The Uninstaller may not remove all (.dll) files. The only fix I know of is to change the ProductName in the Setup