Visual Studio 2017 - VSIX Package stops working after updating NuGet packages - visual-studio-2017

Steps to reproduce:
Open Visual Studio 2017. Select File.. New.. Project..
From the New Project dialog, select Extensibility.. VSIX Project..
Select the new Project from the Solution Explorer. Right Click and Add.. New Item.. Extensibility.. Custom Command..
You now have a complete custom command built from the standard templates. Run it in the debugger. You'll get a experimental instance of Visual Studio. From the menus, select Tools... Invoke Command1... Your custom command works!
Hit 'OK' and exit the experimental instance of Visual Studio.
Now, back in the original solution, click Tools.. NuGet Package Manager.. Manage NuGet Packages for Solution...
In the Updates tab, you'll see there are many updates to the standard packages included in the template. Select them all and update them. Repeat until all your packages have been updated. You will likely need to restart VS during the process.
Build your VSIX package again. You may have to supress the warning around this statement:
public static async Task InitializeAsync(AsyncPackage package)
{
// Verify the current thread is the UI thread - the call to AddCommand in Command1's constructor requires
// the UI thread.
#pragma warning disable VSTHRD109 // Switch instead of assert in async methods
ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD109 // Switch instead of assert in async methods
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new Command1(package, commandService);
}
Debug your VSIX package again.
Select Tools... Invoke Command 1...
You get an error: The 'Command1Package' package did not load correctly.
If you follow the instructions to the %AppData% directory and read the activity log, you'll see that the Microsoft.VisualStudio.Threading 15.8.0.0 assembly can't be loaded.
Could not load file or assembly 'Microsoft.VisualStudio.Threading, Version=15.8.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Threading, Version=15.8.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

There are many ways to fix this (mess). Here is one
first, configure your Visual Studio 2017's Nuget to use the new Package Reference mode. https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files:
delete the legacy packages.config file.
remove all existing references (see the picture below)
edit the .csproj manually and remove all lines that contain "..packages..." stuff, including all lines that check for some nuget presences, and also the associated imports and tasks.
add Microsoft.VisualStudio.Shell.15.0 and Newtonsoft.Json as a nuget packages. You should now see something like this (note the new nuget references with the blue icon):
you should be able to compile and run successfully
For a few months now, everytime I face impossible nuget issues, that's what I do. I copy the old packages.config somewhere, delete it from the project, remember the "root" packages, remove every reference, check the csproj, and add the new references from nuget (trying to add the fewest possible so the child references are ok). Nuget is the future for all references now (we'll have to bite the bullet whether we like it or not), even for Visual Studio ones.

Related

MSBuild to apply a nuget package to a project at build time

I have a cmake project that builds fine on Linux and that I want to build also on Windows. The code is portable and is made of C++ so... it should build. The only thing is that, on Windows, I need to use nuget to restore some packages, cpprestsdk is one of them. Now when I run
cmake .
CMake will generate solution files and projects files that I don't want to include in my VCS at all. The thing I want MSBuild to do is to apply the packages contained in my packages.config to all the project files found in the project directory.
Anyone knows how?
The thing I want MSBuild to do is to apply the packages contained in my packages.config to all the project files found in the project directory. Anyone knows how?
I am afraid you can not do such things. That because whether you are using MSBuild or NuGet to do this thing, you have to use to the nuget.exe to do it. However, install nuget packages to the project file relies on VS capabilities not nuget.exe and nuget team not plan to bring it to the exe.
The NuGet Command Line does not actually install any packages. The install command is actually doing a restore operation.
This means that nuget.exe install will only download and extract the package into the output location. It will not modify the project file. Although, the package manager console seem to offer "Install-Package" for doing this, but you have to open each project files with Visual Studio and execute Install-Package in the package manager console for each project files, which is not what you want. So you could not enable this script outside of visual studio.
So we could not use MSBuild to apply the packages contained in the packages.config to all the project files found in the project directory.
You can refer to this thread and this thread for details.
Hope this helps.

VS2017 Installer project output does not replace the current installation

I have a standard windows forms application that is being deployed using the VS2017 setup project. When opening the setup project using the "File System", I added to the application folder the following:
Primary output from the win forms app.
The EPPlus library's dll.
Some excel files.
The setup project gives the output .msi package just fine. The problem is, when I run the .msi output after building the setup project (of course after building the source project) and run the application, I do not see my updates, even the files on C:\Program Files .... directory are not modified. I tried changing the product code and the increasing the version and it does not work. My questions are:
Besides removing and installing the program again, is there anyway to make the installer package actually updating the software's installation?
How to avoid the problem in #1 no matter how much I update the software?
What is the cause and how to avoid this error "Another version of this product is already installed"? I'm not sure of what I did for it to pop up.
If I want some part of the source code to be in a separate dll, is it as simple as adding a class library project and adding its output to the setup project?
Thank you very much.
The way you do the upgrade is to use the RemovePreviousVersions project setting. The steps are:
Increment the setup project's version and accept the changes, this will include a change of ProductCode.
Make sure that RemovePreviousVersions is set true.
The UpgradeCode (setup project properties) needs to be the same so don't change it.
Increment the file versions of the binaries that need updating (that's the standard rule about updating versioned binaries).
The resulting MSI will do a major upgrade (in Windows Installer terminology) and upgrade the older version, replacing it with your new product MSI. Note that an upgrade will work only with the same context of install. An Everyone will not upgrade a Just me, so that will result in two entries in Programs and Features. Doing the install creating a verbose log and searching foe FindRelatedProducts entries will tell you if it found the upgrade or not. msiexec /I [path to msi file] /l*vx [path to a text log file]
There's a longer explanation here:
https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/?_ga=2.138201520.1662048302.1514485579-1682631157.1514485579
which is old but relevant. and doesn't mention the requirement to update binary file versions (it wasn't needed with early VS setup projects).

Unnecessary project rebuilds when unit testing in Visual Studio

I know about this question (and answers), but despite trying all the suggested options I am still stuck.
I have a solution with multiple projects, but for this particular case let's say I've got my ExampleProjectA and a corresponding unit test project ExampleProjectATest. The first one is added as a reference to the test project - not via Visual Studio's "Project References" but as a link to the DLL (something like "..\Path\$(Config)\ExampleProjectA.dll") - this is due to build server requirements in our company, but the problem also existed when we still had "Project References".
Building and then running a single unit test works fine
Changing just a single letter in a unit test and then letting the test run always results in a rebuild of ExampleProjectA, even though this shouldn't be necessary
Setting all (there were only a few) files in ExampleProjectA from "Copy always" to "Copy if newer" in their respective properties didn't help
Checking the checkbox under Tools => Options => Projects and Solutions => Build an Run (see below) also didn't change anything
To see if there was any more information available, I changed the build output settings to diagnostic. Each time a rebuild of ExampleProjectA is triggered, the first line in the output windows is
1>Project 'ExampleProjectATest' is not up to date. Input file 'c:\tfs\mysolution-dev\exampleprojectatest\myfolder\namegeneratortest.cs' is modified after output file 'C:\tfs\mysolution-dev\exampleprojectatest\bin\Release\exampleprojectatest.pdb'.
The class name written to the window (e.g. namegeneratortest.cs) changes according to which test file I change.
Not sure why this message comes up, but the next step was to disable the debugging information as shown below under Project properties => Build => Advanced => Output => Debug Info => None:
Still the same, nothing's changed.
Another thing I tried was to check the timestamps of the files contained in my solution folder (as there was a case where a user had a file with a future timestamp - see linked post) - to no avail.
Last thing I tried was to change the build settings in the Configuration Manager to a different target platform - some settings wouldn't let me build the solution successfully, some other settings did, but the problem described persisted, so no change.
The behaviour is similar (not the same though) with both the Visual Studio Test Runner and the one provided by ReSharper.
Visual Studio Test Runner
Project 'ExampleProject' is not up to date. Input file 'C:\tfs\mysolution-dev\exampleprojecta\Views\Shared\someview.cshtml' is modified after output file 'C:\tfs\mysolution-dev\exampleprojecta\bin\exampleprojecta.pdb'.
ReSharper Test Runner
Project 'ExampleProjectATest' is not up to date. Input file 'c:\tfs\mysolution-dev\exampleprojectatest\myfolder\namegeneratortest.cs' is modified after output file 'C:\tfs\mysolution-dev\exampleprojectatest\bin\Release\exampleprojectatest.pdb'.
I'm using Visual Studio 2013 Premium Edition with ReSharper 8.2 and the latest updates, the projects in our solution file are in C#.
Update
To clarify - the first line in the output window does show that the test project has to be rebuilt - this is fine. The following lines, however, indicate that also ExampleProjectA has to be rebuilt, which shouldn't be necessary. Subsequent messages to the output window also show that other projects (referenced from ExampleProjectA have to be rebuilt.
Update 2
Despite installing Update 4, nothing has changed.
For my case the solution was to change the build action of a config file from "Copy always" to "Copy if newer". It took a while to find as I had to change the build output details to get the details about which file was causing the error, e.g.
Project 'xyz' is not up to date. Project item 'c:\my\path\web.config.dev' has 'Copy to Output Directory' attribute set to 'Copy always'.
From my experience it can also happen that different file names are shown when building multiple times, so make sure you have the right one and / or build again if the problem persists.
Also have a look at this question and its answers to find some more information.
I have worked around this problem by deleting the .pdb file in the \obj folder. It seems that visual studio is checking file modification time to decide if it should build or not the project (in your case ExampleProjectA) and the .cshtml is newer than the pdb. But when launching the build, project changes in .cshtml files are not triggering the .pdb rebuild, so the problem remains.
By deleting the .pdb in \obj folder (not in \bin as the file there is copied from \obj and would keep the old modification time) the modification time for the .pdb is newer than the .cshtml and the VS doesn't need to build the project before running the tests. Of course this only works until the next time you modify a .cshtml file, that's why I qualify it as just a workaround.
Check what version of Visual Studio 2013 you are using. Update 1 has a pretty big issue where it rebuilds everything. See: https://connect.microsoft.com/VisualStudio/feedback/details/811112/unnecessary-solution-rebuild-on-each-test-run
Upgrading to Update 3 did the trick!
I'm not sure if Resharper could affect things as well. I suggest temporarily uninstalling it.

Teamcity and register dll

I'm trying to build a project with TeamCity Professional 6.5.2
I have a MVC Visual Studio 2010 project using a visual foxpro dll.
The build fails because the dll is not registered.
How can I register that dll in the build machine, as part of the build process?
Thanks!!
There are two different scenarios Rodrigo, your scenario will fall into one of these:
Assemblies which can be referenced by the project: Wherever possible, include dependent assemblies in your source control repository (the 10th Commandment), usually in a "libs" folder which is referenced by the necessary projects. This centralises all your dependencies, makes it easy for new developers to get started and solves your TeamCity build problem.
Assemblies which need GAC installation: There are times when the assembly simply has to be installed in the GAC (i.e. RightFax). Frankly, the easiest thing to do in this case is just to install the damn thing in the GAC. It's an exception and whilst some people will philosophically argue against it, alternatives can get a bit complex (i.e. automating installation as part of the build), and for money I'd rather invest the time elsewhere.
Installing assemblies on each machine (dev, build, prod) will make future updates and any continuous integration system difficult to maintain in the future.
It would be better to create a folder in your working directory (I call it "Resources") which contains a folder for each group of DLLs. Then you just reference the assembly directly from the Project each time. You get duplicate DLLs across different projects, but it keeps everything very clean and simple.
In Visual Studio 2010 you can download a little utility called NuGut which I believes helps to manage assemblies in a better way.
It is a bad idea to register all DLLs on build agent machine, sometime you can find out that you have to install Visual Studio on a build agent machine, for instance ;)
I would suggest to place such libraries along with your code base in Source Control system (I assume you are using it), and just reference lib's folder by declaring a MSBUild property like
<PropertyGroup>
<LibFolder>$(PathFromCommandLineOrJustHardCodedPath)</LibFolder>
</PropertyGroup>
And then before doing a Build/Compile just copy files from $(LibFolder) into the build $(OutputFolder) using standard MSBuild command Copy by specifying source and destination files, and thats it.
To force TeamCity to pickup Lib (dlls) files from VCS folder just add path mapping into the:
TeamCity Configuration Settings -> Edit Build Configuration -> VCS Root settings -> Client Mapping
EDIT:
In your case looks like you have integration test which depends on external COm Server which you need to launch, so you can programatically registr this DLL, for instance in TestSetup, and then do not forget to unregister it in test TearDown.
Anyway you have to just reference this DLL as
VS Project -> Add Existing Item -> Add as Link
+ set
Copy to Output Directory -> Copy if newer
How-To register COM dll: see this SO post
Finally I added a prebuild event in Visual Studio running the regsvr32 command. The dll was in a known location, so I referenced this way:
regsvr32 /s $(SolutionDir)Lib\ProjDataAccess\ProjDataAccess.dll
Agree with Troy Hunt.
For a Continuous Integration with TeamCity 8.0.2 where you need an assembly (custom made shared assembly) reference from GAC, do the following.
1. Add the assembly to the build pack (In my case its nuget package).
2. Before starting the build process (MSBuild, Visual Studio etc), register the assembly to GAC with the help of a command line build runner.
3. Continue with the build process.
By following the above steps, if you are using MSBuild, the build process can link to a valid reference from GAC, which can produce an expected build result.
In my case, where the code refers a custom component from GAC, MSBuild ignored the assembly reference and completed the build process without an exception. But the deployment with the build output failed. To overcome this situation, I've used the give steps.
Note: It is mandatory that the TeamCity agent needs to run under an elevated user account. Else the addition to GAC won't be permitted and the build process can fail.

Help configuring MSpec

rig: win7 64bit, vs2010, mvc v2, TestDriven.Net 3.0, Reshaper 5.0, MSpec 0.3
i recently started a new project and want to use mspec.
(1) copied Machine.Specifications.ReSharperRunner.5.0.dll and Machine.Specifications.dll to JetBrains\ReSharper\5.0\Bin\Plugins\Machine.Specifications (2) copied Machine.Specifications.TDNetRunner.dll to TestDriven.NET 3\Machine.Specifications
when i try to run the test i get this error: System.IO.FileNotFoundException: Could not load file or assembly 'Machine.Specifications
i don't know where this error is coming from.
vs2010 menu -> ReSharper ->Plugins shows the MSpec plugin. vs2010 menu ->ReSharper -> Options -> Tools -> Unit Testing also shows the MSpec unit testing provider but it doesn't show any details when i click on it as does MSTest and nUnit.
i found this: http://marcinobel.com/index.php/mspec-bdd-installer/ which didn't work. i also tried this: http://eduncan911.com/blog/registering-mspec-runners-for-testdriven-net-on-windows-x64.aspx which also didn't work. now i fear i screwed my registry.
any guidance?
full error:
Test 'F:Tests.OTBRadio.Tasks.AlbumTasksSpecs.when_the_album_tasks_are_asked_to_get_all.context' failed: Could not load file or assembly 'Machine.Specifications, Version=0.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Machine.Specifications, Version=0.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'Machine.Specifications, Version=0.3.0.0, Culture=neutral, PublicKeyToken=null'
at Machine.Specifications.TDNetRunner.SpecificationRunner.RunMember(ITestListener testListener, Assembly assembly, MemberInfo member)
at TestDriven.TestRunner.AdaptorTestRunner.Run(ITestListener testListener, ITraceListener traceListener, String assemblyPath, String testPath)
at TestDriven.TestRunner.ThreadTestRunner.Runner.Run()
You do not need to copy Machine.Specifications.TDNetRunner.dll anywhere, just place it in your project's tools or lib directory, i.e. where you keep your project's dependencies. The project containing the MSpec tests will reference the Machine.Specifications.dll from this directory. TestDriven.Net >=2.24 will be able to pick up the TD.Net runner as long as Machine.Specifications.dll.tdnet is located in the same directory. An example how I like to organize my tools directory can be found here.
Your ReSharper 5.0 plugin directory looks good to me. However, I've had users reporting that when you unzip the MSpec zip file (that you likely downloaded from http://teamcity.codebetter.com) using Explorer, Windows marks the extracted DLLs as being downloaded from the Internet.
Can you please make sure that Windows does not block the DLLs in <ReSharper 5.0>\bin\plugins by opening each DLL's properties and clicking "Unblock" on the first property page. In case the "Unblock" button is not displayed, your files are okay. In that case, please post here and we'll see how we can your MSpec plugin working.
After changing any dll you should clean up project - so you don't have any errors in fresh project.
I also had the same problem and I fixed it by cloning a copy of MSpec off Github (https://github.com/machine/machine.specifications).
Then in the "Source" folder I ran one of the batch files (in my case build-4.0-debug.cmd) which created "Machine.Specifications.dll" in "xxx\Source\Build\Debug".
I removed the references to the "old" dll, cleaned up my project, copied over the old dll with the new dll I obtained in the previous step, rebuilt and that did the trick.