Why MSTest does not copy referenced project libraries? - dll

I have a Visual Studio solution with a C# dll project. This solution has also a test project which references the output of the C# dll project. The referenced project dll has set Copy Local = true.
If I run this test from the Visual Studio, it works fine.
But if I run it from the MSBuild task, for some reason MSTest does not copy the referenced C# dll to the MSTest working folder, so the test fails.
The weird thing is, that all the other referenced libaries are copied to the MSTest working folder.
And if I put a
[DeploymentItem(#"PleaseCopyThis.dll")]
before my test method, finally it is copied to the MSTest working folder and my test runs fine.
But why does Visual Studio copy only the referenced dlls which are not part of the solution, but does not copy the referenced project dlls?

So I have found this article: https://web-beta.archive.org/web/20140803214948/http://www.dotnetthoughts.net:80/mstest-exe-does-not-deploy-all-items/
Seems an mstest issue.
Because i just had the same issue I figured a way to fix it. In my case the referenced dll's where never actually used directly from the testproject (altough they were used by using reflection).
To solve it I added a testclass with the following code:
[AssemblyInitialize]
public static void InitializeReferencedAssemblies(TestContext context)
{
ObjectInAssemblyX dummy = new ObjectInAssemblyX();
ObjectInAssemblyY dummy2 = new ObjectInAssemblyY();
}
Now they are used so they will be copied

Related

Visual Studio Code DotNet Core Project "ProjectName.dll" does not exist

I received new project file. Its actually .NET Core Worker Service Project. Created using VS Code. I tried to Manually build the service. but in there no have any dll file. because I only changed the project name after its received. Now I tried to run my project. but I got error. its says
launch: program 'C:My Folders\Glm'
Projects\DBDataService\bin\Debug\netcoreapp5.0\win7-x64\'DBDataService.dll' does not exist
Can you please tell me how to setup my local environment with dll file in VS Code. I am new to VS code actually. How to manually setup dll file in project
VSCode was looking for the DBDataService.dll program, but could not find it.
You only need to configure your environment and then correctly define everything (especially "programs") in your launch.json.
Try to change,
"program": "${file}"
${file} is a predefined variable in VS Code for the current opened file. Refer to:
https://code.visualstudio.com/docs/editor/variables-reference
You can also refer to this post, which may help you:
C# - VS Code - launch:program ... does not exist
Create a debugging file:
https://code.visualstudio.com/docs/editor/debugging

VB.net .exe cannot be run from another computer. Missing assemblies for ClosedXML

I must put this program into production today, and I can't get it to run independently.
In the program, I have included NuGet package "Imports ClosedXML.Excel" and use it to create spreadsheets. When I build my executable, and try to run it from another computer, it cannot find the ClosedXML and Documentformat.OpenXml assemblies.
I checked in References that "Copy Local" was = True for ClosedXML and Documentformat.OpenXml, but it's not working. I found another website that mentioned Global Assembly Cache, and that if the dependency is in there, it will not be included in the Build .exe.
I am running Visual Studio Professional 2017. I am in over my head on this one, so if you have answer (and I hope you do), please try to provide it in elementary terms I can understand.
Sometimes issue is solved by individually adding application files inside the following menu
Go to Publish-->Application Files
Select Show all files
Under Publish Status
Set the files you need to Include [not include(auto)]

MS Fakes on VSO Build

I have a set of unit tests that use Shims from MS Fakes to test some static methods. I am currently using 4 fake assemblies, all of which reside in a single assembly. This fakes assembly is then referenced by the unit test assemblies that need it.
When we run locally in VS2013, all is fine, but when we try to do a build in Visual Studio Online, it fails with the following type of error:
MockLogManager.cs (25): 'ShimJsonLogger' does not contain a definition for 'LogGet'
Any ideas why it seems to be building the ShimJsonLogger but not giving it all of the properties we need?

Indirect references in VB.NET solution breaking build

Project A references Projects B. Project B references Project C. Project A does not reference Project C.
This builds fine locally. However, on the build server it errors out because Project A does not reference Project C.
Error:
error BC30009: Reference required to assembly 'ProjectC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' containing the implemented interface 'ProjectC.IFoo'. Add one to your project.
How can I catch this before committing?
Edit:
Here's more info on my issue: http://sstjean.blogspot.com/2006/11/msbuild-cant-find-secondary-references.html
Here are two things you can do as a best practice to ensure your projects are referenced correctly and MSBuild will be able to find your referenced projects correctly.
Use project references instead of referencing dll's. Create a folder called dependencies or libs and place any referenced dll's within this folder.
Check the build order and project dependencies tab for each project by right clicking project and selecting project build order. Ensure that every reference in your project is being built by that project.
MSBuild does not know what a .sln file is. MSBuild reads and parses the .sln file to determine the build order of projects. By having project references MSBuild will be able to traverse and build the projects in the correct order. See below link for more information.
This link also helps explain why you would see different behavior and how to catch it.
Visual Studio Integration (MSBuild)
Within Visual Studio, the solution file and project build ordering are controlled by Visual Studio itself. When building a solution with msbuild.exe on the command line, MSBuild parses the solution file and orders the project builds. In both cases the projects are built individually in dependency order, and project to project references are not traversed. In contrast, when individual projects are built with msbuild.exe, project to project references are traversed.
When building inside Visual Studio, the property $(BuildingInsideVisualStudio) is set to true. This can be used in your project or .targets files to cause the build to behave differently.
Go to your project references and right click Oracle.DataAccess then go to properties and in properties page make sure that specific version is false and copy to local is set to true.

TFS 2010 - WebDeployment - indirect referenced assembly missing

We've got the following problem:
solution-structure:
AutofacRegistration
References: Repositories.dll
WebApplication
References: AutofacRegistration.dll
In our web application we are referencing the AutofacRegistration.dll and this assembly references Repositories.dll. Repositories.dll is instantiated on runtime per IOC-Container.
When we build the solution in VS2010 and browse the web app everything is working fine, as expected.
When we use our build server(TFS 2010) und use the web deployment, the Repositories.dll is missing the web-app\bin folder and we got a runtime exception(when we want to instantiated a class in Repositories.dll)
But Repositories.dll is in our drop location, so the web deployment target does not copy this file, any ideas how to solve this??
Have you tried a copy task from the BuildTemp location to where your Web Deployment Project can pick up the file it needs?
<Copy SourceFiles="$(OutDir)\Repositories.dll" DestinationFiles="web-ap\bin\Repositories.dll" />
The paths will need modified but you get the idea. I do a similar function in MSBuild to move a dll for our installer to pickup.