TFS Build with PostSharp Debug | Any CPU - tfs

I have a .Net project (framework 4.0) that references PostSharp assembly (version 2.1). The project is configured for Debug and Release with Any CPU.
I'm trying to build that project on TFS (2012), created a build definition where I add two workspaces:
- One workspace with the directory where is the PostSharp.dll assembly
- One workspace where the .csproj file is.
The configuration I added is Debug | Any CPU.
When I attempt to build, it states that everything works fine but warns that my project doesn't have an OutputPath configured. After googling, I found out that it was related with the Any CPU, that should be AnyCPU without the space.
But if I do this, when TFS attempts to build my project it states that The type or namespace name "PostSharp" could not be found.
So if I use Any CPU TFS seems to recognize PostSharp, but if I use AnyCPU seems to recognize my project but not PostSharp.
Is there any workaround for this?
Thank you.

In the meantime I found the answer, it was the Build agent folder for my PostSharp assembly directory that was wrong. Works fine now.

Related

TFS Build - MSBuild 14 x64 memory leak or too high memory consumption

Recently we've upgraded our solution (with hundreds of projects) to target .NET 4.6.1. We've also changed the ToolsVersion to 14.0. Locally on dev machines everything works fine, but once we changed in the TFS templates to use the new msbuild (14.0) the memory usage during the actual build went sky high - over 8 GB's of memory used by the msbuild process.
Did anyone else had such a problem? Any ideas what can cause it to go that high?
P.S. We have no project references, only assembly references. Each project as a post-build event does copy assembly dll into specific common folder and then it does GAC it.
Looks like it's a known bug which was fixed in the master branch of the MSBuild on the github.
https://github.com/Microsoft/msbuild/commit/f8f33a9da283b300a14a1540414d0358b01bfa46

How to resolve reference errors in Code Analysis of MVC.net project using Team City

When using Team City for CI builds there is an option to use the Resharper command line tools to run Code Analysis inspection of the code as one of the build steps.
I have this working with reference library projects but the mvc.net project in the solution fails with reference errors:
One or more types required to compile a dynamic expression cannot be
found. Are you missing references to Microsoft.CSharp.dll and
System.Core.dll?
Even with the default Microsoft template there are over 200 errors and they seem to all come from the razor views. (The project compiles and deploys from the build server correctly and FXCop also runs successfully, this seems to be an issue just for resharper tool.)
I can run the resharper code inspection in visual studio without errors.
In Team City I just have a default Inspection (.NET) build running pointing at the .sln file.
We are using Resharper Command Line Tools 9.1.201 as provided with TeamCity 9.0.4
What configuration or additional steps can I take to get the resharper command line tool to resolve mvc view references on the build server?
If resolving the references is not possible, can the razor views be excluded from the analysis without needing to add each exclusion to the command line?
For future reference, I just had the same issue. Digging through the build log, I noticed a seemingly unrelated warning:
The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found.
I retargeted my project to .NET 4.6 and installed the .NET 4.6 targeting pack, and the code inspection errors are gone. Unfortunately, I don't know if just installing the .NET 4.5.2 targeting pack would have solved the issue.

TFS Build missing .targets files intermittently

Our builds are failing on the TFS build server with the same errors from time to time.
I'm getting this message on one of our projects (the error refers to a WebApi project):
The imported project "C:\Program Files
(x86)\MSBuild\12.0\bin\Microsoft.CompactFramework.CSharp.targets" was
not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
And this one on another project (on smart device projects):
The imported project "C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
Usually this means that the file is not there and it should be a matter of either installing the tool that contains the targets files or manually copy them from a developer machine. I've seen it before in that situation and solved it easily since it is a trivial problem.
Problem is, the files are there! The builds seem to fail randomly, which is extremely obscure to me. If we select 'Retry Build' a few times, the build goes through normally. Some times the build just works the first time, and then it starts showing this error. I failed to detect any pattern as to when it happens.
There is absolutely nothing special about the files themselves. I thought they were missing some permissions somehow, but they have the same security settings as other accompanying files.
I have no idea what to even investigate here. The message points out that a file is missing but the file is there. The fact that it occurs intermittently is even more problematic.
This is happening on a TFS 2013 build machine. Visual Studio 2013 Ultimate was installed on it after installing TFS. We have another build VM in the company using TFS2012 and I've never seen such odd behavior.
EDIT:
I forgot to mention it, but there are also a bunch of random warnings on the build containing the web project. They only appear when the error about the .targets file occurs, and do not show up on the other build. Perhaps it is related with the fact that one is .Net4.5 (the web) and the other is .Net3.5cf:
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (989): The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (989): The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (1635): There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\mscorlib.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (1635): There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "System.Data", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (989): The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (1635): There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\mscorlib.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (1635): There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "System.Data", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (989): The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
EDIT 2:
Ok. After Dylan's comment, I went to the build logs to "confirm" that there was only one agent running the builds, and to my surprise:
Successful Build: Run on agent (reserved build agent Build2014 - Agent1)
Failed Build: Run on agent (reserved build agent TFS2013 - Agent1)
Build2014 is our build VM, and TFS2013 is our source control one.
When TFS 2013 was installed on TFS2013, a build agent was installed alongside it on the same machine. The controller that was installed on a separate machine also had an agent with the same name. This means that the controller was picking one of them and whenever they hit the TFS machine the build failed (because there is no dev environment there on purpose).
Removing the wrongly installed agent on the TFS machine is the way to go here.
Are you sure your builds are always running on the same build agent/server? Is it possible you have multiple build agents setup and it only works on certain ones?

TFS 2012 build exclude some project from compilation process

I have some strange behavior in my automatic build. When I open solution properties in build workspace I find that there is one project not checked in configuration to build, and my build fails. When I open this solution from TFS source control, this project is checked and build in VS pass successfully. Does anyone have an idea of what can exclude the project from solution configuration in build process? Could there be any other reason for this problem?
Check out if the project is included in the Configuration Manager window (solution context menu), for the given flavor (Release/Debug) and CPU. TFS build is probably using another configuration.

TFS does not build projects correctly

HI
I am trying to build my solution using TFS but it seems to skips the projects which have dependencies.
e.g Proj B depends on Proj A , then it builds only Proj A and not Proj B.
Also if i try to build the projects individually instead of the solution then it does not create the release folder. It says that the output path is not found.
Any help is much appreciated
thanks
Is the SLN file in question converted from an older version of Visual Studio?
I've found that sometimes, like when you upgrade from a VS2003 SLN file to a VS2008 SLN file, it fails in MSBuild (which is what TFS is doing essentially).
Try making a new SLN file in VS2008 (or whatever version you're using) with the same project and see if that fixes it...
If you right-click the solution, one option you'll have is dependencies. Make sure that the projects are correctly setup there, even though they may reference each other the dependencies on the solution itself may not be complete or accurate...and this is what MSBuild uses.
Have a look in the configuration manager and make sure that the build you are running has those projects selected to build.
It may be you are running the Debug configuration for your local build and then running Release on the TFS server and it's not configured the same.

Resources