Visual Studio doesn't put binaries of Unity project to output folder - c#

I’m working on a solution containing default Unity project (Assembly-CSharp).
I added a test project to the solution with a reference to Assembly-CSharp. According to IntelliSense, the test project does see the types from Assembly-CSharp, however when I’m trying to build the solution, I’m getting the following error:
Metadata file 'MyProjectFolder\Temp\bin\Debug\Assembly-CSharp.dll' could not be found.
Thus, I'm not able to run unit tests on my Unity project.
Indeed, when I’m building the Unity projects, the .\Temp\bin\Debug folder remains empty even though the build is recognized as successful by VS.

The problem is caused by Disable the full build of projects setting which is new in Unity Tools extension. It prevents the binaries to be created, which speeds up situations when they're not actually being used, like when starting the debugger.
Turning this setting off in Visual Studio settings fixes the issue. Now all build products are placed in ./Temp/bin/Debug folder and I can run unit tests.
Feature request
I made a feature request to VS to make it possible to define this setting at solution level, so that you can have 1 solution for speed and 1 for unit testing. I hope it will get enough votes up: https://developercommunity.visualstudio.com/idea/798543/make-it-possible-to-manipulate-the-disable-the-ful.html

I have the same problem, and regenerate project files did the trick.
Edit => Preferences => External Tools => Regenerate Project Files

Related

How to compile a .sln file that contains errors?

I am making a modified version of Smart Steam Emu and it does contain some errors. I don't have the time and knowledge to fix some of these errors and there are tons. These errors (from what I know) also exist in the stable build.
I need to test something and I was wondering to compile the project if it contains errors. Thanks!
IDE: Visual Studio 2013
OS: Windows 10 Creators Update
As Ken said, you cannot compile the solution without resolving all the errors.
That said, there are a couple of ways if you just want to test a particular project, but the errors must be in the project that’s not referenced by the project you want to test.
First you need to Set the Project you want to test as Startup project
Method 1: Remove the erroneous project from solution. Run the project you want to test.
Method 2: Run the solution. Select “Yes” when VS prompts you with question that you want to continue to run with errors.
Hope this is helpful!

Debugging a vstemplate wizard

For a game engine called duality (https://duality.adamslair.net/) I want to make a solution template that will create the necessary projects and all the files needed for duality to function. This includes files and folders that are not part of a project themselves.
In order to achieve this iam trying to make a wizard that can generate the files/folder structure I need as I understood that templates alone are quite limited in this aspect. I followed this tutorial: https://msdn.microsoft.com/en-us/library/ms185301.aspx.
However when I debug this and try to create the solution it says it failed but not why or how. Breakpoints are not being hit either since the symbols are not loaded.
This is the error I get when trying to create a project using my template:
When I comment out the WizardExtension node in the vstemplate it works fine
So how do I change my project so that it does load the symbols and I can debug it? Iam using vs2017.
Included is my project:
DualityTemplate
Turns out it was because the platform was set to Any Cpu. When I changed this to x86 it worked without problems.
This is most likely cause by the extension deciding to run in 64 bit while visual studio is only 32 bit.

How can I change Visual Studio's build order for reflection based project dependencies?

I have the need to dynamically load different versions of the same dll's depending on various situations.
The dll's are created as part of the build process for other projects within the same solution.
For example
/MainSolution
/MainProject - Loads dll's using reflection dynamically
/AbstractProject
/DllProject1
/DllProject2
DllProject1 and DllProject2 need to be built before MainProject. MainProject depends on AbstractProject, and through reflection DllProject1/DllProject2. However Visual studio currently forces MainProject to build before DllProject1 and DllProject2. How can I get Visual Studio to build DllProject1/DllProject2 before MainProject?
Visual Studio allows you to set explicit build dependencies in the solution (as opposed to implicity dependencies e.g. from traversing your references). Just right-click on your solution and find the Project Dependencies menu item:
The dialog that opens will allow you to set build dependencies and show you the calculated build order (you can affect the order by changing the dependencies).
The solution I found was to do the following:
Open up the .sln file, and change the order in which they projects are listed. Dropping MainProject down to the bottom. Then when I opened up the solution, it had DllProject1 and DllProject2 listed above MainProject in the build order.
Edit: While this works, there is no rhyme or reason for how it works. Randomly switching the order results in randomly changing the build order for projects that have the same dependents.
I tried a neat trick and it worked - we have a fairly big solution and it was difficult to maintain the dependencies just right to get the solution build order working from build to build -- it happened that one of our little console test apps happened to be first up in the build order - so I faked the dependencies for that little app and it fixed up the build order for the entire solution - KLUDGE - yes

How do I configure a Visual Studio C# unit test solution to accept different runtime configurations?

What I have
I have a unit test Visual Studio C# Solution (which runs webdriver tests, not that that's necessarily relevant). It runs via TeamCity. Currently the environment is hard-coded to "Dev" in one of the .cs files, and I manually change the code locally to run elsewhere when required.
What I want
A way to setup two projects in TeamCity - one to run on "Dev" environment and the other on "Test" environment. Obviously I can't use hard-coded values so I need some sort of set of configuration files that can be chosen at runtime, or possibly some sort of build parameters - but I have no clue how to do this or what will work.
(I didn't mention TeamCity in the question as it is not 100% relevant / just provides context --- as long as I can run the unit tests eg from the command prompt with parameters that can be passed in, that would do the trick.)
What I've tried
From what I've asked around, I don't believe I can use web.config as it's not a web solution but a unit test solution. I believe there is a mechanism to tell Configuration Manager what web.config file to use, so I'm hoping there's a similar mechanism that can be used for Unit Test projects. I've tried hunting down information on "build configurations" on "unit test projects" and a range of other searches, but it's a nightmare finding anything relevant.
Can someone point me in the right direction? I'm good with my basic programming, but if it requires messing around with configurations or build parameters, then I might need a more explicit 'how-to' from you.
Thanks in advance.
Check this extension for Visual Studio
https://visualstudiogallery.msdn.microsoft.com/579d3a78-3bdd-497c-bc21-aa6e6abbc859
This allows you to create different config files for different build type. You need to create different build types each with a config file specific to that build type.
Ok as per my comments above, I tried a solution here: https://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5
IT WORKED.
I'm now able to create App.Config transforms that automatically link to a Build Configuration. I can then specify the build configuration inside TeamCity.
The only trick was that the "Rebuild" target didn't work if there were no code changes but there was a difference in Configuration. (They use the same directory of the same Agent, and a rebuild is necessary). The workaround for this is to tick the 'Clean all files before build' option in TeamCity Version Control settings.

Successful Visual Studio C# build does not create assembly

I am using Visual Studio 2005, .NET 2.0
I am not really sure yet under what circumstances it happens, but here is the scenario:
I have a solution with a project structure like this: A library project Foo, a library project Bar which references Foo, and a library project Quux which references Foo and Bar.
Compiling fails with the Error message "Metadata file 'Foo.dll' could not be found" from Bar, and "Metadata file 'Foo.dll' could not be found" and "Metadata file 'Bar.dll' could not be found" from Quux.
Looking in my target directory (I have a combined target directory for all 3 projects), it is empty, so no project at all is compiled. Now I can get that Bar and Quux fail if there is no output from Foo. Problem is: Why does Foo silently fail? There is no error from it, and just building Foo instead of the entire solution works fine.
The "funny" thing is, after just pushing the build button again, the Foo.dll file appears, Bar no longer complains but does not produce any output file either, and Quux complains about missing Bar.dll. Pushing the button again, the Bar.dll appears, there are no more errors but no Quux.dll. Only after pushing the button yet again, the Quux.dll appears, once again with no errors.
The project dependencies are all set correctly, the solution build order says exactly the right thing.
I have even tried creating a new solution and new project files, then adding the sources again to those. No joy, either. Same thing happens.
I am completely stumped. Does anyone know a way out of this mess?
You should have separate output directory for each project. Each time a project builds, it clears the output directory, so it won't find any dependencies on the next one.
Don't fear losing any DLLs, they'll be copied on each bin directory where they are needed.
I think a work around to your problem could be using post build events that deletes previous version of your dlls and copies the new ones to your combined target directory.
When you set up the three projects to work this way, you will find that you are compiling each project to it's correspondent bin folder and to a combined target directory. There is a second thing you should do if you decide to work with this, set up for each project in your solution a reference path pointing to the combined target directory. Compiling order must still exist.
This way each project dll will be found in the combined target directory, each time you compile.
Although, this solution has it's own problems such as when a post-build event forgets to wrok properly; but it's rare.
Hope this helps
The problem is build order. If some project depends on another then that second project must be built first. Use build dependencies in the solution properties to overcome this.
Check you build order so that all seems right there..
Try to run a clean solution and build again is this when it happens?
Drag your project file into note pad and Find with "Import" tag
and replace that tag with this
Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"
Its should work
For reasons unknown, this happened to me with Visual Studio 2013 in the middle of a morning's work. One build, it was updating the dll, the next, it just wasn't, even though the build seemed to go smoothly. I finally addressed it by deleting the existing dll. With no pre-existing dll, the build had to provide a new one.
I agree that each project should have its own target directory. I have tried to get cute with this and it always causes more trouble than whatever I was trying to get around.
I have a vs19 , 5 project solution. I just added a new console app. THis app started suddenly compiling without complaint but did not produce files. the unit test project that depends on it complained.
I did the usual
clean / rebuild
clean / rebuild each project in order
check the project dependencies and the build order
restart vis studio (in know its 2020 and i still have to restart vs sometimes)
faced w/ the prospect of just creating a new project, i decided to try one other thing
removed all references to other projects
commented out all the code that depended on these.
i was left with pretty much a main() that returned a 0
this compiled and produced files
one by one i added the references back until everything was there.
uncommented the code.
at the end of this exercise things worked.
I can not tell you what changed.
Thought I would offer this as a trouble shooting method.

Categories