简体   繁体   English

如何使用TFS Build构建VS2010 MakeFile项目(vcxproj)(无VS 2010)

[英]How to build a VS2010 MakeFile project (vcxproj) with TFS Build (No VS 2010)

I have a project that was building fine in VS 2008, and then we installed and started using TFS Build, and then we upgraded to TFS 2010. Everything was still fine and building correctly (after I implemented our new build process that made everything very nice with a single-click build initiation from any remote Visual Studio 2010 client). 我有一个在VS 2008中正常构建的项目,然后我们安装并开始使用TFS Build,然后我们升级到TFS 2010.一切都很好并且构建正确(在我实现新的构建过程之后,使一切都非常好从任何远程Visual Studio 2010客户端单击构建启动)。 Visual Studio did not need to be installed on the Build Agent. Visual Studio不需要安装在Build Agent上。 I'm trying very hard ( very hard) not to install Visual Studio on the Build Agent because my understanding is that it's not necessary, and we're not licensed to install it on a non-development machine. 我非常努力( 非常努力)不在构建代理上安装Visual Studio,因为我的理解是没有必要,并且我们没有许可将它安装在非开发机器上。

Now I tried upgrading the solution to VS 2010, still targeting .NET 3.5 because it's an assembly targeted for SQL Server CLR procedures, and SQL Server doesn't support .NET 4.0 yet. 现在我尝试将解决方案升级到VS 2010,仍然针对.NET 3.5,因为它是针对SQL Server CLR过程的程序集,而SQL Server还不支持.NET 4.0。 But I simply cannot make it build any more under TFS Build. 但我根本无法在TFS Build下进行构建。 I can't seem to get a consistent error message from TFS Build and from an MS Build command line, but I think it has something to do with Microsoft.Cpp.Targets not being in C:\\Program Files\\MSBuild\\ because I haven't installed Visual Studio. 我似乎无法从TFS Build和MS Build命令行获得一致的错误消息,但我认为它与Microsoft.Cpp.Targets不在C:\\ Program Files \\ MSBuild \\中有关,因为我没有没有安装Visual Studio。 I did install the Microsoft Windows SDK 7.1 so that I could run the .NET 4.0 SDK tools like svcutil for some other .NET 4.0 projects, but nothing seems to install what this build wants. 我确实安装了Microsoft Windows SDK 7.1,这样我就可以为其他一些.NET 4.0项目运行像svcutil这样的.NET 4.0 SDK工具,但似乎没有安装这个构建所需的东西。 The error TFS build gives me is: TFS构建错误给我的是:

C:\\TFSBld[...]\\GenerateLanguage\\GenerateLanguage.vcxproj(46,3): error MSB4019: The imported project "C:\\Microsoft.Cpp.Default.props" was not found. C:\\ TFSBld [...] \\ GenerateLanguage \\ GenerateLanguage.vcxproj(46,3):错误MSB4019:找不到导入的项目“C:\\ Microsoft.Cpp.Default.props”。 Confirm that the path in the declaration is correct, and that the file exists on disk. 确认声明中的路径是否正确,以及该文件是否存在于磁盘上。

And when I click on that error it takes me to this line in the vcxproj file: 当我点击该错误时,它会将我带到vcxproj文件中的这一行:

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

All I really need to do in this project is run resgen to generate resources files from resx files, and compile them into sattelite assemblies. 我真正需要在这个项目中做的就是运行resgen来从resx文件生成资源文件,并将它们编译成sattelite程序集。 I was using a makefile build to do this, manually running resgen (I think it was because I can't find a way to compile sattelite assemblies as a stand-alone solution any other way), and then compile those into a DLL (I can't remember how that worked now, but I think it was manually running AL.exe to compile DLL files from resources files). 我正在使用makefile构建来执行此操作,手动运行resgen(我认为这是因为我无法找到将sattelite程序集编译为独立解决方案的方法),然后将它们编译成DLL(I不记得现在怎么工作,但我认为是手动运行AL.exe从资源文件编译DLL文件)。 So basically I just need to run command lines to build this project, and I can't seem to find a reasonable way to do it without throwing out the entire project and editing the TFS build script to run a bunch of hard-coded command lines instead. 所以基本上我只需要运行命令行来构建这个项目,我似乎找不到合理的方法来做到这一点而不抛弃整个项目并编辑TFS构建脚本来运行一堆硬编码的命令行代替。 There's got to be a better way. 必须有一个更好的方法。

I've been at this all day, and tried writing my own .targets file and .xml property sheets to take the place of the standard file, but it's way over my head. 我整天都在这里,并尝试编写自己的.targets文件和.xml属性表来代替标准文件,但它已经超出了我的想象。 I tried simply deleting the lines, but then MSBuild complains that there's no "Build" target. 我试过简单地删除这些行,但是然后MSBuild抱怨没有“Build”目标。 I tried adding a dummy to the vcxproj file, but then it didn't seem to run the pre- and post-build steps where all the work is done. 我尝试在vcxproj文件中添加一个虚拟对象,但是它似乎没有运行完成所有工作的构建前和构建后步骤。

The Microsoft Windows SDK 7.1 has several installation options. Microsoft Windows SDK 7.1有几个安装选项。 Having only the ".NET Development" child "Tools" checked is apparently not enough to build vcxproj projects, even if they don't include any C++ code (only pre- and post-build steps). 仅检查“.NET开发”子项“工具”显然不足以构建vcxproj项目,即使它们不包含任何C ++代码(仅在构建前和构建后步骤)。 Adding the "Visual C++ compilers" option and fully selecting the "Intellisense and Reference Assemblies" checkbox installs the necessary files and settings. 添加“Visual C ++编译器”选项并完全选择“智能感知和参考组件”复选框将安装必要的文件和设置。 I'm not sure if both are necessary, but that combination did work for me. 我不确定两者是否都是必要的,但这种组合对我有用。

I have devised a somewhat complex, but functional work around involving the following steps. 我已经设计了一个涉及以下步骤的有点复杂但功能性的工作。

  1. Copy these files from C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0 on a system where VS2010 is installed -- check them into source control so they are retrieved as part of the workspace: 在安装了VS2010的系统上从C:\\ Program Files(x86)\\ MSBuild \\ Microsoft.Cpp \\ v4.0复制这些文件 - 将它们检入源代码管理中,以便将它们作为工作区的一部分进行检索:
    • Microsoft.Build.CPPTasks.Common.dll Microsoft.Build.CPPTasks.Common.dll
    • Microsoft.BuildSteps.targets Microsoft.BuildSteps.targets
    • Microsoft.Cl.Common.props Microsoft.Cl.Common.props
    • Microsoft.Cpp.Default.props Microsoft.Cpp.Default.props
    • Microsoft.Cpp.props Microsoft.Cpp.props
    • Microsoft.Cpp.targets Microsoft.Cpp.targets
    • Microsoft.CppBuild.targets Microsoft.CppBuild.targets
    • Microsoft.CppCommon.targets Microsoft.CppCommon.targets
    • Microsoft.Link.Common.props Microsoft.Link.Common.props
    • Microsoft.MakeFile.targets Microsoft.MakeFile.targets
    • Platforms\\Win32\\Microsoft.Cpp.Win32.default.props 平台\\ WIN32 \\ Microsoft.Cpp.Win32.default.props
    • Platforms\\Win32\\Microsoft.Cpp.Win32.props 平台\\ WIN32 \\ Microsoft.Cpp.Win32.props
    • Platfotms\\Win32\\Microsoft.Cpp.Win32.targets Platfotms \\ WIN32 \\ Microsoft.Cpp.Win32.targets
  2. Change the vcxproj file to refer to the relative path where the workspace puts those files instead of $(VCTargetsPath). 更改vcxproj文件以引用工作空间放置这些文件而不是$(VCTargetsPath)的相对路径。
  3. Change lines (in all those files) to use attribute AssemblyFile="Microsoft.Build.CPPTasks.Common.dll" instead of referring to this using the AsssemblyName attribute. 更改行(在所有这些文件中)以使用属性AssemblyFile =“Microsoft.Build.CPPTasks.Common.dll”而不是使用AsssemblyName属性引用它。
  4. Delete "$(VCTargetsPath)\\" in the files at the root of the new location so that it finds its sibling files instead of trying to refer to the non-existent VCTargetsPath macro. 删除新位置根目录下的文件中的“$(VCTargetsPath)\\”,以便找到其兄弟文件,而不是尝试引用不存在的VCTargetsPath宏。 You can find instances that you missed by trying to run a command line build with MSBuild on the machine without VS 2010 and looking at the error messages. 您可以在没有VS 2010的计算机上尝试使用MSBuild运行命令行构建并查看错误消息,从而找到错过的实例。
  5. Similarly replace $(VCTargetsPath) in child directory files with relative paths. 同样,用相对路径替换子目录文件中的$(VCTargetsPath)。
  6. At the end of the file Microsoft.Cpp.Win32.targets, comment out the "<VCMessage Code="MSB8008" ... />" line and the following related <Import>. 在文件Microsoft.Cpp.Win32.targets的末尾,注释掉“<VCMessage Code =”MSB8008“... />”行和以下相关的<Import>。
  7. Trial and error, run command line build and see what else I may have forgotten to mention. 试验和错误,运行命令行构建,看看还有什么我可能忘记提及。 I think that was most of it. 我认为这是其中的大部分内容。

An improved alternative to BlueMonkMN is to add BlueMonkMN的改进替代方案是添加

<PropertyGroup>
  <VCTargetsPath Condition="'$(VCTargetsPath)' == ''">[path_to_the_fileset_listed]</VCTargetsPath>
</PropertyGroup>

as a level 1 child near the top of the vcxproj. 作为vcxproj顶部附近的1级孩子。

The path could include an environment variable or some other well-known path containing variable. 该路径可以包括环境变量或包含变量的一些其他众所周知的路径。

This makes less of an an intrusion and is easier to revert than changing lots of lines. 这样可以减少入侵,并且比更改大量行更容易还原。

An even more simple approach with adding an environment variable for VCTargetsPath : VCTargetsPath添加环境变量的更简单方法:

  1. Locate the CPP Msbuild Folder mentioned by BlueMonkMN 找到BlueMonkMN提到的CPP Msbuild文件夹
    • eg C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\V120 例如C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\V120
  2. Open Windows environment variables 打开Windows环境变量
    • Control Panel > System > Advanced Settings > Advanced > Environment Variables
  3. Add a new user variable with: 添加一个新的用户变量:
    • Name: VCTargetsPath 名称: VCTargetsPath
    • Value: [your path to MsBuild targets from step 1] 价值:[您从第1步开始的MsBuild目标路径]
  4. Restart Visual Studio. 重新启动Visual Studio。
  5. Done. 完成。 Your project should build now. 你的项目现在应该建立。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM