I have c# project with .csproj extension, in this file I am referring a .vcxproj (C++). When I try to build the project with msbuild, the build fails with following error:
Program.cs(13,25): error CS0246: The type or namespace name 'CppLibrary' could not be found (are you missing a using di
rective or an assembly reference?) [C:\Work\CppTest\CSharp\CSharp.csproj]
Done Building Project "C:\Work\CppTest\CSharp\CSharp.csproj" (default targets) -- FAILED.
Done Building Project "C:\Work\CppTest\CppTest.sln" (default targets) -- FAILED.
How can we use .vcxproj in .csproj?
I make use of the the model validation feature like this:
[StringLength(60, MinimumLength = 3)]
[Required]
But when I start the application I get this:
Author.cs(8,6): error CS0246: The type or namespace name 'StringLengthAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(8,6): error CS0246: The type or namespace name 'StringLength' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(9,6): error CS0246: The type or namespace name 'RequiredAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(9,6): error CS0246: The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(8,23): error CS0246: The type or namespace name 'MinimumLength' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(11,6): error CS0246: The type or namespace name 'StringLengthAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(11,6): error CS0246: The type or namespace name 'StringLength' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(12,6): error CS0246: The type or namespace name 'RequiredAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(12,6): error CS0246: The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(11,23): error CS0246: The type or namespace name 'MinimumLength' could not be found (are you missing a using directive or an assembly reference?)
I cannot find out what package I'm missing. My guess was Microsoft.AspNetCore.Mvc.DataAnnotations but that seems not to be it.
So what dependency do I need here?
The dependency seems correct.
But just importing the library/nuget package doesn't mean you can just use it. You also need to put using System.ComponentModel.DataAnnotations (or using System.ComponentModel.Annotations at the top of your *.cs file.
Or just hit Ctrl+. on the error to let VS suggest you the correct namespace.
You have to first install entity framework from the nuget package then only you will be able to get the using System.ComponentModel.Annotations.
I am trying to compile this Json.NET code:
using Newtonsoft.Json;
...
MyDesc d = JsonConvert.DeserializeObject<MyDesc>(jsonInput);
...
with this command via mono (on ubuntu):
$ mcs Main.cs -lib:/home/username/JsonNET/Net40/Newtonsoft.Json.dll
But i am getting "no assembly reference"-error:
error CS0246: The type or namespace name `Newtonsoft' could not be found.
Are you missing an assembly reference
What is the correct Json.NET Mono assebmly reference?
(-lib option looks right for this, but it does not work -lib:PATH1[,PATHn] Specifies the location of referenced assemblies )
The mono compiler command to reference other assemblies is -r:PATH/TO/ASSEMBLY. You should try this with the current version of mono.
$ mcs Main.cs -r:/home/username/JsonNET/Net40/Newtonsoft.Json.dll
Reference: http://linux.die.net/man/1/mcs or type into your shell:
$ man mcs
I input this command
gmcs -t:library Program.cs
and get this error
Program.cs(6,14): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
I get I have to give it the paths and everything, but how? can't find the way to do it
gmcs targets the .NET 2.0 profile, Task didn't exist back then.
On a recent Mono just use mcs, as gmcs is deprecated and was removed from Mono 4.0.
I'm trying to run msbuild in Jenkins.
When it reaches the UniTest-Project an error occures:
Project "C:\Program Files (x86)\Jenkins\jobs\***\workspace\***.sln" (1) is building "C:\Program Files (x86)\Jenkins\jobs\***\workspace\***.unitTests\***.unitTests.csproj" (4) on node 0 (default targets).
Project file contains ToolsVersion="4.0", which is not supported by this version of MSBuild. Treating the project as if it had ToolsVersion="3.5".
ResolveAssemblyReferences:
Primary reference "Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL".
Could not find dependent files. Could not load file or assembly 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets : warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
For SearchPath "{Registry:Software\Microsoft\.NetFramework,v4.0,AssemblyFoldersEx}".
Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Microsoft.VisualStudio.QualityTools.UnitTestFramework.exe", but it didn't exist.
Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.exe", but it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
Considered "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v2.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.exe", but it didn't exist.
Considered "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v2.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
Considered "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v4.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.exe", but it didn't exist.
Considered "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v4.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
Considered "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.exe", but it didn't exist.
Considered "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
Considered "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.exe", but it didn't exist.
CalculatorServiceTest.cs(1,17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
CalculatorServiceTest.cs(11,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(11,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(24,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(24,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(37,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(37,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(6,6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?)
CalculatorServiceTest.cs(6,6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?)
Done Building Project "C:\Program Files (x86)\Jenkins\jobs\***\workspace\***.unitTests\***.unitTests.csproj" (default targets) -- FAILED.
Done Building Project "C:\Program Files (x86)\Jenkins\jobs\***\workspace\***.sln" (default targets) -- FAILED.
Build FAILED.
Any suggestions what the problem could be? Running ms build from the command works for the solution and without any additional parameters when the project was compiles in VS bevor. After a clean solution the same errors occur. Must be some parameter or reference problem; Line two talks bout v4 and v3.5 problems; but i can't figure out how to solve this.
Greets
Error info directly shows that you use incorrect version of MSBuild
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
Try to rebuild with MSBuild 4.0
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe *.sln /t:rebuild
OR/AND from VS2010 Command Line.
I had a similar problem which seemed to be caused by running Jenkins as a service under the SYSTEM account. Somehow cmd.exe was not referencing all the necessary environment variables to be able to find my NUnit assemblies.
If you're running Jenkins as a service, try setting it to run as your user account and see if that helps.
Im building from the default windows cmd using:
C:...\MSBuild.exe *.sln
The solution-projects are all 3.5; only the Unit-Test Project is 4.0 (as you can't change this)
I just mentioned, that building it that way works, when i build it first with VS and don't deleted (clean solution) the binaries. Never mind.
How do i have to use msbuild from cmd to build a *.sln including unittests?