Microsoft.VisualStudio.Tools.Office.targets missing - msbuild

I am installing a build agent on a virtual machine (using GoCD) and my goal is trying to keep it as light as possible, i.e., installing only MSBuild and avoid installing visual studio.
One of my projects uses OfficeTools and when compiling the build I get the following error:
C:\GoAgent1\pipelines\ProjectRepo\Office\MyProject.Office.Excel2007.UnderwritingNotes\MyProject.Office.Excel2007.UnderwritingNotes.csproj(365,3):
error MSB4019: The imported project "C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
OfficeTools\Microsoft.VisualStudio.Tools.Office.targets doesn't exist!
For that I will need to install "Office Tools for Visual Studio" which depends on Visual Studio (in this case VS2015 or 14.0).
One solution is copying this folder from my development machine but is sounds a bit messy!
So I was wondering if there are standalone versions that I can plug into MSBuild without installing Visual Studio. Any suggestion?

Related

Using MSBuild to build SSDT projects with VS2017 fails

I am trying to set up continuous integration of .sqlproj SSDT projects on our windows server 2016 server.
In order to do this I have installed VS2017 and SSDT tools onto the server to get the required tools. I have also installed MS build tools 2017.
The issue I am currently having is regarding what looks to be miss-matched versions of installed ms build tools and ssdt.
The command i am using to run the build is as follows:
C:\\Windows\Microsoft.NET\\Framework64\\v4.0.30319\\MSBuild.exe /p:VisualStudioVersion=15.0 /property:MSBuildExtensionsPath="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\" /property:VsInstallRoot="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\" DPAP-SQL-Slim.sln
The two switches passed there are to set two environment parameters that the .sqlproj file is expecting to find when run through Visual studio. This is done because MSBuild does not supply them by default.
The error i am currently getting is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(477,5): error MSB4062: The "SqlModelResolutionTask" task could not be loaded from the assembly C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\IDE\Extensions\Microsoft\SQLDB\Dac\140\Microsoft.Data.Tools.Schema.Tasks.Sql.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Now, i can see from running the command: gacutil /l in the VS2017 command prompt that the apparently installed version of the Microsoft.Build.Utilities.Core dll is v14: Microsoft.Build.Conversion.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
Am i missing something key here? It appears that installing build tools 2017 did not in-fact update the GAC and register the correct DLLs.
Do not use the msbuild.exe included in .NET Framework (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe). It is old and does not support some features of newer msbuild versions.
Always use the version of MSBuild installed with visual studio or the build tools. Depending on the version of VS installed, this could be
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe
Starting in VS 2017, MSBuild is also not installed system-wide but many versions (e.g. VS 2017 preview versions, different editions like Build Tools / Enterprise / Community etc.) can be installed side-by-side, which is why you won't find these MSBuild assemblies in the GAC.
I was having this issue building a SQL Server project on a CI/CD pipeline. None of the pre-built build tasks on Azure DevOps would work for me. I solved this by avoiding to add a SQL Server project to the solution.
I achieved this by using an MSBuild SDK, capable of producing a SQL Server Data-Tier Application package (.dacpac) from the set of SQL scripts. By adding this second project to the solution, I managed to continue taking advantage of linking the project to a live database through SQL Server Object Explorer on Visual Studio. I gave a more detailed explanation in this answer.

TeamCity/.sqlproj build via MSBuild -- FAILED

It all started with the VS2017 runner type within TC. It was failing without any errors or hints (except the (default targets) -- FAILED. message on the solution level). I narrowed it down to the .sqlproj'ects. These are not building via MSBuild, they do compile perfectly within VS2017 on the build agent.
I was blaming SSDT for it... but I guess I checked everything. This is the problem which bubbles up to the solution level within the TC build:
I noticed that for VS2017 SSDT comes with the VS setup. The "Workload" "Data storage and processing" is installed and so is "SQL Server Data Tools" under "Individual components".
I noticed on https://learn.microsoft.com/EN-US/sql/ssdt/download-sql-server-data-tools-ssdt the sentence "If you are using SSDT with Visual Studio 2017, install the AS and RS components". Did it. Nothing changed. SSDT is also installed separately for previous versions.
This stack is related but it didn't help me.
Any other ideas?
I came a step further. Beside VS the Build Tools are installed as well on the build agent and TeamCity's runner for VS2017 obviously uses MSBuild from the Build Tools.
As you can see above I was reproducing the issue with MSBuild from the Build Tools as well.
If I pick the MSBuild "version" of VS2017 it works like a charm (as it does right within VS).
To make it short:
DOES NOT WORK
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin
WORKS
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin
I found a blog post from Lukie Briner, his last paragraph pointed me to the solution (thank you buddy!).
Still don't know why/how this can happen, maybe it is related to the order of the installations of Build Tools, SSDT, Visual Studio etc.?
The reason: SSDT was missing in the Build Tools and its version of MSBuild.
What I have done:
Copy the SSDT folder from
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0
to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0.
WOW! I finally see a REAL error message:
Now I had to copy SQLDB and SQLEditor (I think SQLCommon already existed in the destination folder, if not it should also be copied) from
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft
to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\Extensions\Microsoft
and BOOM...
And yes, the VS2017 runner from TeamCity is also happy with it.
Seems like the issue with Build Tools and SSDT has been solved now and you don't have to mess with manual copy of targets directories anymore (Visual Studio Build Tools 2017 v15.9.8).
Just open the Visual Studio Installed on the build agent server
Modify Build Tools installation
Select to install the "Data storage and processing tools"
Modify
Build should work now.

msbuild fails to compile vsto project

We recently installed a new development environment (Windows 10) from scratch with Visual Studio 2017 but we cannot manage to make msbuild compile a Microsoft Office Addin for Word (vsto).
Within the Visual Studio installer we made sure to include the required components for Office Development.
It throws the following error (german translated to english)
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" was not found. Also, tried to find "OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" [...]
However, the project builds fine within Visual Studio.
On the old system, everything works fine, and i cannot remember having to configure anything at all.
You need to install Office build tools when installing Build Tools for Visual Studio 2017
In my case, I managed to get around the issue by copying the folder
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio
from the development environment (the old environment in your case) to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio
on the build environment (the new environment in your case). I would have thought that one should be able to simply get the relevant targets from the Build Tools for Visual Studio 2017 but that appears not to be the case.
After reinstalling everything it works now.
I guess back then when we set up this machine, the build tools setup was bugged or something.
Now we could install everything we needed for the buildtools using the visual studio installer and it works like a charm.
Okay, so I've worked through this one now. The problem was caused by me using Windows\Microsoft.NET\Framework64\v4...\Msbuild.exe.
It looks as though running msbuild from this location results in it not being able to implicitly locate many of the assemblies and build utilities required to build a VSTO project.
I resolved the problem by switching to using C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe

Visual Studio 2015 - a lot of Packages are missing

So I recently bought a new computer. And now I wanted to install visual studio 2015. So I did. But now the problem is that i cant create a new project because i cant select a vb.net form or anything else and also im getting these error messages saying:
The 'ErrorListPackage' package did not load correctly
The'VisualStudioPackage' package did not load correctly
The Microsoft.visual studio package did not load correctly
anyone has a solution for this? because I'm kinda getting a bit frustrated now.
I tried a complete uninstall and install and it didnt work. I tried copying folders from my laptop to my new pc but also that didn't work. Also switching frameworks doesn't do anything. I also never experienced this problem before but can this problem occure because I have 2 drives?? Seems odd but I think I'm also going to do an uninstall again and then try the .iso installer and see if that helps.
So this is how I fixed it for myself.
I removed all files and folders that are linked to visual studio
C:\Program Files\Microsoft Visual Studio 12.0
C:\Program Files (x86)\Microsoft Visual Studio 12.0
C:\Program Files (x86)\Microsoft Visual Studio 14.0
C:\Users\name\AppData\Roaming\Microsoft\VisualStudio
C:\Users\name\AppData\Local\Microsoft\VisualStudio
C:\Users\name\AppData\Local\Microsoft\VisualStudio Services
C:\Users\name\AppData\Local\Microsoft\VSCommon
C:\Users\name\AppData\Local\Microsoft\VsGraphics
After I deleted all of those folders I deleted the regkeys located:
HKLM > SOFTWARE > Microsoft > Visual Studio
After that I started the visual studio installer with admin rights.
And now I can create a project :)
This usually indicates an issue with an extension which ships with some dependent assemblies which Visual Studio itself (or another extension) also depends on. When these dependencies are different versions, it's not predictable which version will load.
To solve your problem, first disable your extensions and add-ins, then close Visual Studio, clear the ComponentModelCache folder under:
C:\Users\{username}\AppData\Local\Microsoft\VisualStudio\12.0\ComponentModelCache
And start Visual Studio again.
This should clear the immediate issue.
Now enable each extension one-by-one restarting Visual Studio every time to see if the issues come back.
To dive deeper into the underlying issue, you could look into all the extensions under these folders:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions
C:\Users\{user}\AppData\Local\Microsoft\VisualStudio\12.0\Extensions
Look for assemblies from Microsoft itself (commonly found are Microsoft.TeamFoundation.* and Microsoft.VisualStudio. in folders containing an extension that did not originate from Microsoft. These extensions are common culprits for these issues.
If you want to dig deeper, consider using fuslogvw from the Windows SDK to see which assemblies are loaded and which exact versions they are. You can also look into the Visual Studio logs after the issue surfaces to see what underlying cause there may be. The log should be available under:
%AppData%\Microsoft\VisualStudio\14.0\ActivityLog.XML

How does TFPT.exe find what workspace to work in?

In using tfpt from the command, I'm getting the error:
PS D:\Main Line> tfpt uu /noget
Unable to determine the workspace.
Here I'm trying to use the Undo Unchanged command, but I've seen this error with other commands too. The path I'm at is the exact path that is mapped in my TFS workspace. I also tried this which doesn't work either
PS D:\Main Line> tfpt uu /recursive /noget 'D:\Main Line'
Unable to determine the workspace.
I thought it was just using the current path to figure it out, but I can't get it to work right. Does anyone know how this works?
I ran into this same issue, I found the answer at the bottom of the page in one of the help files that came with The power tools. (TFPTCommandLineTool.mht)
Errors
TFPT Error: Unable to determine the workspace
When running tfpt using a command that works with Version Control, you may receive one of the errors:
Unable to determine the workspace
Unable to determine the source control server
Solutions:
Run tfpt.exe from within a directory that is already mapped to Team Foundation source control.
Update your local workspace cache using the tf workspaces command. The tf.exe tool is available in the subfolder Common7\IDE of your Visual Studio installation folder. If you launch a Visual Studio command prompt, you can then run the following command (which depends on your versions of TFS/VisualStudio - you should use the version that matches version of TFPT you are using, e.g. if you have TFPT for VS2015, use TF from a VS2015 command prompt):
VS 2008-2013 / TFS 2008:
tf workspaces /s:serverURL
VS 2010-2013 / TFS 2010 (and probably later versions as well):
tf workspaces /collection:collectionURL
VS 2008 / TFS 2010 (and probably later versions as well):
tf workspaces /s:collectionURL
If you have recently installed Visual Studio 2012, you might have to connect it to the same TFS server/collection you were using in Visual Studio 2010.
When using tf workspaces /s:serverURL make sure you use the right tf.exe!
I had the same problem and was stuck because I used the tf.exe from:
\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
and not the one from:
\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
For Visual Studio 2017 users
I had the same problem when trying to run the tfpt command line on a fresh machine installation with VS215 and VS2017 installed. The latest version for the tfpt tool at the time of writing is from TFS Power Tools 2015. That means the local workspace mapping has to be loaded in VS2015 first before the tfpt tool can find the workspace.
Since my team is using VS2017, I only did the workspace mapping in this Visual Studio version. When I opened the VS2017 developer command prompt to use this tool, I got the 'Unable to determine the workspace' message.
To solve this I opened VS2015 and connect the Team Explorer to the TFS server. It immediately recognizes the workspace mapping that was made under VS2017. After this the tfpt tool works correctly under VS2015 and VS2017 developer command prompts.
I tried all of this and still i got the same error. The error is generic enough to represent multiple issues, i guess..
re-installing TFPT from
https://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f
fixed the issue for me.
Actually, although I believe that in some cases these workarounds may fix things, they do not work in all cases. And I strongly suspect that ultimately this points to what could be considered a bug somewhere in the PowerTools code. The reason I say this is that the tf workspace command has no problem detecting the workspace on my machine from the VS Command console, but from that very same console with all of the same path info, TFPT cannot detect it on my lap top no matter what I try. I just got this laptop and installed VS 2010, 2012 and 2013, along with the respective Power Tools installs, and pointed to a suite of projects that currently spans several TFS 2010 and TFS 2012 instances. Because of this many-to-many relationship, I suspect there is an incorrect assembly reference somewhere, some combination of factors, GAC, Path, Environment Variables, VS Installations, TFS repositories. In each VS version I attempted to run the TFPT 2010 executable from the VS 2010 Command, and so on with the remaining versions, and tried the above workspace cache updates in all their forms... nothing. But using the same project I connected from an old server with VS 2010 and TFPT 2010 installed and ran the same command perfectly. So I think it has to do with what is running on your system, and in the future I will be much more skeptical about running the different versions side-by-side.