When I install MongoDB.Driver from Nuget Packages in VS it installs as expected, but when I try to use MongoDB.Bson in a class it says "The type or namespace name 'Bson' does not exist in the namesppace 'MongoDB' (are you missing an assembly reference?)"
To have the solution reference external libraries, place the library files, and all required dependencies, into a “\Plugins” folder in your project. You can get these from NuGet and unpack them. Unity will then add the references to your solution. This isn’t guaranteed, as the library might reference other libraries that are simply incompatible with Unity, but this is the process in general.
Related
Maybe just an oversight on my part, but I can't make sense of this:
I have the reference to System.Drawing in my project tree within the references
I have the correct using statement using System.Drawing;
I can access other members of this namepace
According to the docs, bitmap should be within this namespace.
However, if I try use a bitmap, I get the following error:
Error CS0246 The type or namespace name 'Bitmap' could not be found
(are you missing a using directive or an assembly reference?)
VS19-IntelliSense suggests to install the package System.Drawing.Common, however if I do that, I get yet another error, stating:
The type name 'Bitmap' could not be found in the namespace
'System.Drawing'. This type has been forwarded to assembly
'System.Drawing.
How can I resolve this issue to actually use the Bitmap class?
Copy the System.Drawing.dll from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 into your Unity project folder. I put mine under Assets/Plugins/System.Drawing.dll.
This version will contain the Bitmap class. You will still have an error in the editor, but everything will compile fine and you should be able to use Bitmap in Visual Studio.
A problem you may now encounter when using certain types from this dll (e.g. Color, RectangleF) is that Unity gets confused between the 4.0 and 2.0 versions of the dll files. The only solution I found to resolve this is to change Api compatibility Level from .NET Standard 2.0 to 4.0 under Edit > Project Settings... > Player. .
If you choose not to do this, you will find that there is System.Drawing in the C:/Program Files/Unity/Hub/Editor/2020.2.0f1/Editor/Data/NetStandard/ref/2.0.0/netstandard.dll. Removing this dll will cause Unity to complain until you restore it.
There are solutions suggesting to modify C:\Program Files\Unity\Hub\Editor\2020.2.0f1\Editor\Data\NetStandard\compat\2.0.0\shims\netfx\System.Drawing.dll or C:\Program Files\Unity\Hub\Editor\2020.2.0f1\Editor\Data\MonoBleedingEdge\lib\mono\4.5\System.Drawing.dll, but I would advice against this as it would impact other projects using the same Unity version.
A little background. I'm relatively new to the NuGet package manager system, but so far I have installed a few packages.
The question I have regarding NuGet is how do we know how to reference the installed package using the using directive?
I know that NuGet packages have a descriptions in the NuGet package manager. However, they don't always show how to import the packages. So I mostly end up Googling for examples of the package that I install to see if there is an example that shows what the using directive is to import that package.
Recently I have installed the package Selenium.WebDriver.PhantomJS.Xplatform I have difficulty finding examples online that show where the package resides and how to import it.
The problem is that a NuGet package can contain zero or more assemblies that can be added as references to the project in which you install it. So there is no one-on-one relationship between packages and assemblies; neither is there between namespaces and assemblies (an assembly can contain multiple namespaces, or the same namespace can be used by multiple assemblies), so neither is there between package names and the names of the assemblies therein nor the namespaces therein.
So: you have to know what you're doing. There is a reason you chose to install Selenium.WebDriver.PhantomJS.Xplatform. Somebody must have told you to, or you must have read it somewhere that you should do that.
When you do come along a situation where you hear or read "You should install package Foo!", then that source should also give you examples for how to use the types contained within those packages. And that's where you should read which namespaces to import in order to do so.
Some libraries also don't need any code to function; they're plugin-like additions to other libraries that you should already have in place in order to use them.
Usually nuget packages have a github repository or maybe a website.
Sometimes you can find examples, sometimes you have to go through source code.
I went to their Github repository and found that one of the namespaces they use is: OpenQA.Selenium.
You can check their source code here.
when I put that using directive it tells me The type or namespace
name...
All above describes the details about how to know using directive, so add some details to clarify why nuget not responsible for it, what in VS responsible for it and what the Intellisense(the option ) can do for us.
NuGet packages how to know their using directive?
Nuget in VS is just a Package Manager, it won't know the using directive.
For the most nuget packages, they contain at least one assembly, when you consume the package, actually you add reference to the assemblies from the package. So it's equivalent to that you have some assemblies developed by someone, then you reference them locally(add=>reference=>browse) in your project. So in this situation Nuget won't know how to use the assemblies with using...
(Here we just talk about the assemblies in package, nuget package has much more advantage from its install.ps1,build content...)
What actually do this in VS for you is Intellisense, it's responsible for recognizing your using statement in code editor,and help provide quick-info suggestions.(add using namespace,import reference...)
The function you're talking about is Intellisense, not Nuget, and Intellisense is used to check if your using directive is correct, it will search whether the namespace you use exists in referenced assemblies, but it will only display wrong(if can't find) or right, it won't tell you how to use the assemblies and what namespace defined in them! That's something you need to go through source code or research the example, like Vyacheslav and CodeCaster answered.
I'm writing a C# class library for net461 that is consuming a NuGet package. The package adds two assembly references to my project as these are the ones you normally need. But in this special case, I also need to reference a third assembly inside the package. I can easily do this by pointing to the folder beneath Packages folder, but that will give me a version-dependent hint path that will break next time the consumed package is updated.
How can I avoid this scenario? I cannot seem to find any way in VS2017 to do a "deep" assembly reference into the referenced Nuget package...
I am also the author of the consumed package, so I could expose the third assembly as as well, but that would pollute the 99% other projects only needing the two first assembly references.
Thanks in advance
Ulrik
Create another nuget package that references your existing nuget package as a dependency. Then add the additional assembly reference in what is basically a wrapper package. Consume that instead.
Or
Create a copy of the nuget package that includes the assembly reference and add a suffix to the package name. Only issue is you will have to publish two packages whenever you change it. Not sure if it will matter when you have projects using each in the same solution as the dlls should match.
Or
Just include the assembly as a reference and pollute the other projects. I don't think it will hurt.
I'm working on a program that uses a Dymo labelwriter 450, using a custom reference to interact with it from my c# program. I'm using DYMO.Label.Framework
When I sync with GitHub and Travis tries to test the software, it can't compile because it's missing a reference. error CS0246: The type or namespace name 'DYMO' could not be found. Are you missing an assembly reference?
I made sure to add the DLL to the project directory and reference it from the project using a relative path.
Is there something I need to add to the travis config? I can't find the package on NuGet.
Thanks.
Travis works fine with references, even nuget packages are actually referenced by relative path. Make sure your dll is pushed to github and saved to the right place. Project directory (not bin or something) should be the basis of relative path. One more thing to note -- path strings are case-sensitive as travis works on mono.
References like this worked for me:
<Reference Include="Nustache.Core">
<HintPath>..\..\Tools\Rosalia\Nustache.Core.dll</HintPath>
</Reference>
I have created a C# test project in VS2015 RC. it builds locally but when i attempt to build on our CI build server (TeamCity) it fails with errors:
UnitTest1.cs(2,17): error CS0234: The type or namespace name
'VisualStudio' does not exist in the namespace 'Microsoft' (are you
missing an assembly reference?)
[... .Tests.csproj]
UnitTest1.cs(9,10): error CS0246: The type or namespace name
'TestMethod' could not be found (are you missing a using directive or
an assembly reference?)
[... .Tests.csproj]
Clearly this is because the assembly containing these namespaces (Microsoft.VisualStudio.QualityTools.UnitTestFramework) is not on the build server; on my local machine it resides at C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.
I could copy the assembly into my solution so that it becomes part of the codebase but manually moving files feels like a bit of an inelegant hack. I searched around on nuget and found http://www.nuget.org/packages/Microsoft.VisualStudio.QualityTools.UnitTestFramework/ which I figured would do the trick, but installing that package failed with:
Install-Package : Could not install package
'Microsoft.VisualStudio.QualityTools.UnitTestFramework 11.0.50727.1'.
You are trying to install this package into a project that targets
'.NETFramework, Version=v4.5.2', but the package does not contain any
assembly references or content files that are compatible with that
framework
What's my best option of solving this? I'm surprised that creating a test project in VS2015 does not automatically include all the dependencies that I need, though perhaps I'm being naive (I'm something of a fledgling dot netter).
The answer is similar to option 1 in eng.augusto's answer.
Microsoft doesn't provide NuGet for the latest version of Microsoft.VisualStudio.QualityTools.UnitTestFramework,
but rather supplies it as a part of Visual Studio
(normally at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)
I created the folder Microsoft.VisualStudio.QualityTools as a subfolder of my solution and copied:
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Microsoft.VisualStudio.QualityTools.UnitTestFramework.xml
The files should be added to source control (even if DLLs are usually ignored).
Then I changed references in my Test.csproj to refer to a new location.
Hmm I have some ideas, so choose the one that best fits your needs
A simple answer should be mark the DLL to copy local and use a folder like Assemblies in the same folder of the solution and references "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll"
Install Visual Studio in your build server. Sounds nuts but it's the closest to "developer machine" that you have.
Install the DLL in the GAC so you don't have to bother with this.
Fix the NuGet package (Adding a reference for the .NET Framework version) and use it.
Downgrade your .NET Framework version so you can use the NuGet package.
Create your own NuGet server! (and add the reference of the DLLs you need).
IMHO I'd choose the first answer, because it seems to be the "best way" to use NuGet to resolve all your packages problems but you are using a DLL that you don't know if it should be trusted.
In system used in "old" languages like C, or C++ it's common you download the source code and the libraries needed for the code to run so I do not think the NuGet package it's the best solution.
Using the first option you always have the same version and could check the MD5 of the file and know exactly what is running in your build server.
Maybe the real best option should be 6. When you use your own NuGet server to handle your DLLs making your live more awesome and trustable.
For projects created in VS 2017. Adding Nuget package Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated allows to build unit test projects on CI without VS installed on build server:
I was having this issue when trying to use MSBuild on our dev server via our CI/CD process after I was asked to uninstall VS2013 from our dev server by our IT team.
In my case in my build output there were a few lines with the word Considered. What this means is that the build is considering those folders for locations where the file may be located. One of those lines was as follows:
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
I copied Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll from my local machine to that folder on the dev server and the error went away.
Of course Microsoft does a s...t job. To fix this, you need to copy the dll's to some convinint lication and reference them from your ptoject .csproj file.
<HintPath>..\packages\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="QualityTools-Fakes">
<HintPath>..\packages\Microsoft.QualityTools.Testing.Fakes.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
I don't understand why when we add this from VSudio it does not update the same file instead no one has an idea what it does. In Java you have a single file pom.xml or build.gradle, nothing else. In C# there is all sorts of stuff which adds no value but confusion.