MSBuild from command line errors - Reference required to System.Xml - msbuild

I'm creating a batch script which will get latest version of the code of an application, then build it using msbuild. Everything works until the msbuild part. Here's the line that runs msbuild:
C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe "code/Solution.sln" /p:Configuration="Debug"
And the thing errors all over the place - all the errors say something like:
C:\code\project1\codefile1.vb(882): error BC30009: Reference required to assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' containing the implemented interface 'System.Xml.Serialization.IXmlSerializable'. Add one to your project.
Everything builds without errors from from Visual Studio 2008. What's going on here?

This is probably most detailed descriptions on what is going wrong:
MSBuild Can't Find Secondary References
Resolving Binary References in MSBuild
In short:
Your project references assembly X.
X contains a class, that implements interface from assembly Y.
Your project does not reference Y, so MSBuild fails.
Studio acts a bit smarter and finds the second level reference.

Do just what it says and add a reference to System.Xml to your project.
Project->Add Reference

Related

TFS 2015 reference required to assemby

I've a problem with a build with TFS 2015.
I've a simple project that reference B.dll . B.dll use A.dll . The project don't reference A.dll as it don't use it itself.
A.dll & B.dll bothe are company Framework dll stored in the GAC.
[error]LogistiqueTest\Index.aspx.vb(7,14): Error BC30009: Reference required to assembly 'A.DII.Technique.Interfaces, Version=3.5.0.0, Culture=neutral, PublicKeyToken=e60618ca32d203a8' containing the implemented interface 'A.DII.Technique.Interfaces.IGestionException'. Add one to your project.
This is not a big deal, just a reference that's missing. But we don't want to add unecessary references in our projects
Moreover, this problem don't occurs with visual studio (2013 pro)
So I tracked the problem and I saw that :
-> Visual studio retrieve quickly the reference (A.dll) after the "call" of this line
Target "CoreBuild: (TargetId:61)" in file "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets" from project "D:\AgentTFS_02_work\3\s\LogistiqueTest\LogistiqueTest.vbproj" (target "Build" depends on it):
But TFS don't use the same file; it use
"C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets"
The difference between those files is in Microsoft.Common.CurrentVersion.targets, there is some code for resolving assemblies.
So my questions are, is there a way to make TFS build my solution visual studio like ? Force the other target file to be used? Is there another trick to be able to resolve this assembly ?
I tried to add, like i saw in many post around the web, a folder that contains every .dll required, but TFS don't event try to resolve path for A.dll
More information : The exception occurs at the execution of Vbc.exe
because with VS execution the command line has A.dll in the /import section when with TFS it's not added. No problems with MSBuild.exe.
I finally found an anwser :
http://www.nsilverbullet.net/2012/02/17/automatically-resolving-secondary-assembly-references-with-msbuild-and-tfs-build/
I need to add this to the proj file that has problems.
<Target Name="AfterResolveReferences">
<!-- Redefine referencepath to add dependencies-->
<ItemGroup>
<ReferencePath Include="#(ReferenceDependencyPaths)"></ReferencePath>
</ItemGroup>
</Target>

NUnit unable to load dll with String Key Name

I have a project in which I have some C# classes which I am building using csc in my ant script. I have also have written some unit tests which I want to test with NUnit2.6, My test class and actual class refer to one DLL which is compiled with String Key Name (.snk), if I install thi DLL in my GAC (gacutil /i myDLL.dll) everything works fine. As soon as I uninstall this DLL from my gac I get following error for all the test during the build when I try to run my test using NUnit;
Test Error : fromJDynTest1
[exec] System.IO.FileNotFoundException : Could not load file or assembly 'myDLL, Version=5.1.0.0, Culture=neutral, PublicKeyToken=c0409b584f86b2d6' or one of its dependencies. The system cannot find the file specified.
[exec] at fromJDynTest1()
...
...
Does anyone know how to resolve this. Let me know if you need any other information.
Thanks
--
SJunejo
The code you are testing cannot see the assembly in question when you place it in the gac it can see the assembly. You need to ensure that the code you are testing has the assembly in the bin directory when compiled (perhaps copy local is set to false in your project on the assembly reference).
The reason I am sure it is not a dependency (which is mentioned in the message) is because the situation is resolved when the assembly is placed in the gac. This error is not likely caused because the assembly is strongly named.
Failing that the test code refers to the assembly and that test code either doesn't have a reference or has the same problem (not in its compiled directory).
Would help if you posted the actual test or structure of the project.
.net locates assemblies as follows:
Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first.
Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. If it failed before it will fail again now.
Checks the gac. If the assembly is found there, the runtime uses this assembly.
Probes for the assembly (if you open up a .csproj file in a text editor you will see hintpaths, which try and help .net find the assembly).

doing msbuild from the command line: getting errors for the referenced namespace 'Microsoft.VisualStudio.TestTools'

i'm compiling a .net 3.5 solution with msbuild with this line of code:
msbuild.exe n:\temp\Thisnight.sln /p:Configuration=Debug /v:diag
and it gives me this error:
error CS0234: The type or namespace name 'UnitTesting' does not exist in the namespace 'Microsoft.VisualStudio.TestTools' (are you missing an assembly reference?)
i've gotten the latest source which (off course) builds in VS2010 itself.
Can't seem to figure out what i'm missing here....
EDIT
Seeing higher up in the command window this message:
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=neutra
l, 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.
I don't think i have to include this DLL by my project (because it's a MS dll?)
EDIT
What i've seen now: all projects are for the .Net 3.5 framework, but the testproject (which is the one giving me problems) is for the .Net 4.0 framework.
And the weird thing is: i can't change it.
It's a vs2010 solution with web. webservice,winforms,dll,setup and testprojects
did you run vcvars32.bat in your cmd shell?
If you look at the Microsoft.Common.Targets file you will see :
<!--
The SearchPaths property is set to find assemblies in the following order:
(1) Files from current project - indicated by {CandidateAssemblyFiles}
(2) $(ReferencePath) - the reference path property, which comes from the .USER file.
(3) The hintpath from the referenced item itself, indicated by {HintPathFromItem}.
(4) The directory of MSBuild's "target" runtime from GetFrameworkPath.
The "target" runtime folder is the folder of the runtime that MSBuild is a part of.
(5) Registered assembly folders, indicated by {Registry:*,*,*}
(6) Legacy registered assembly folders, indicated by {AssemblyFolders}
(7) Resolve to the GAC.
(8) Treat the reference's Include as if it were a real file name.
(9) Look in the application's output folder (like bin\debug)
-->
VS runs MSBuild in its own environment, I don't know the differences either but did you try adding the lacking assembly path in command line by modifying the AssemblyFolders items. You have a tuto here : http://www.beefycode.com/post/Resolving-Binary-References-in-MSBuild.aspx .
Hope this helps.
try running:
msbuild /version
Make sure it's the 3.5 version and not something older.
Make sure the MS dll is here, or somewhere like that:
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

VB.Net project shows errors on clean in VS2010

my issue is very similar to:
http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-vb/54944/VB-Net-project-throwing-errors-when-executing-Clean-Solution
Typical errors: Unable to load referenced library X
Type IWshRuntimeLibrary.WshShell is not defined.
Interface System.IDisposable is not implemented by this class.
Namespace of type specified in the Imports Z does not contain any public members or cannot be found. Make sure the imported element name does not use any aliases.
This must have to do with a VB.net project configuration. Currently there is a setting "Treat all warnings as errors". I would like to keep that setting, but also resolve these annoying "errors".
I've experienced a similar problem and fixed it by running the following command in the VS command line tool
devenv /resetskippkgs
I'ev had problems executing Clean's via MSBuild in VS2008 when projects were registered for COM interop.
The problem is that the "Clean" target auto-generated for a solution cleans projects in the same order in which they were built.
This causes problems for projects registered for COM when MSBuild attempts to load and then unregister the assembly from COM during a "Clean".The issue occurs if the assembly has a dependency on another project because the dependency will be deleted first and therefore loading the assembly will fail and MSBuild will be unable to unregister it.
A workaround is to change the solution .cache file (which contains the targets auto-generated by MSBuild during "Build") and reverse the order of the "Clean" target. I hacked-together a quick-fix custom build task to do this as a post-build step.
No idea if this was fixed in VS2010 or indeed if this matches your problem since you don't give many specifics in your question ;)

Mono - Could not load file or assembly

i just exported my project to my new imac an loaded my solution into monodevelop.
After the successfully compilation i started the project, and i always getting the same error.
** (/Library/Frameworks/Mono.framework/Versions/2.6.1/lib/mono/2.0/xsp2.exe:1576): WARNING **: The following assembly referenced from /private/var/folders/9y/9ypfv24bEwieHw+Yy+PUsU+++TI/-Tmp-/nhu-temp-aspnet-0/ebc9e2c6/assembly/shadow/7f5f6265/859daf16_fac2cd73_00000001/Centrism.Administration.UI.dll could not be loaded:
Assembly: Centrism.Core (assemblyref_index=3)
Version: 0.0.3688.40278
Public Key: (none)
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/var/folders/9y/9ypfv24bEwieHw+Yy+PUsU+++TI/-Tmp-/nhu-temp-aspnet-0/ebc9e2c6/assembly/shadow/7f5f6265/859daf16_fac2cd73_00000001/).
** (/Library/Frameworks/Mono.framework/Versions/2.6.1/lib/mono/2.0/xsp2.exe:1576): WARNING **: Could not load file or assembly 'Centrism.Core, Version=0.0.3688.40278, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
In other projects the assembly works correct and can be loaded.
I had the same problem with a dll that was in the same path as the application assembly, the problem was that the dll name had a different case than the expected one. So the Abc.dll was missing, in the folder it was named abc.dll, after renaming, it worked.
I guess I'm going to ask the obvious:
Do you have Centrism.Core.dll somewhere that Mono knows about and can get to?
If your project is referencing the Centrism.Administration.UI.dll, and it is not in the GAC on your iMac, the easiest solution would probably be to set the reference to that assembly to "Local Copy". For web projects, this will copy the assembly into the application's Bin directory, where xsp should be able to pick it up.
I had this error when adding a new assembly to an existing project (which itself was referenced by a unit test project).
Because the assembly wasn't included in both projects, the unit test would error out. The solution was to add a Copy tag to the project file:
<Copy SourceFiles="$(ProjectDir)\dlls\NewAssembly.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
Presumably it would also work to add the reference directly to the unit test (this reference is not used directly, so was able to avoid using above).