如果 .net 版本不匹配,则强制构建失败
我们有一些应用程序仍然必须是 2.0,因为它们将在未安装 v3.5 框架的客户端计算机上运行,并且我们希望确保没有代码被插入不属于的代码。我知道3.5框架包括2.0框架。也就是说,我们正在努力确保,如果有人无意中将特定项目的目标版本从 2.0 更改为其他版本,我们的自动化构建将会失败。这种情况不应该发生,但我们会格外小心。
我们认为可能会以某种方式使用 beforeBuild 以及 .csproj 文件中的 TargetFrameworkVersion 。如“如果 TargetFrameworkVersion 不是 2.0,则输出消息并使构建失败”。这是可能的/最好的方法吗?
We have a few apps that still have to be 2.0 because they are going to go on client machines that won't have the v3.5 framework installed, and we want to make sure no code gets slipped in that doesn't belong. I know the 3.5 framework includes the 2.0 framework. That said, we're trying to make sure that if someone inadvertently changes the targeted version on a specific project from 2.0 to something else, our automated builds will fail. This shouldn't happen, but we're trying to be extra careful.
We thought there might be someway using beforeBuild and possibly the TargetFrameworkVersion in the .csproj file. As in "if the TargetFrameworkVersion is not 2.0, output message and fail the build". Is this possible/the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想将相关项目的“目标框架”更改为 .Net Framework 2.0。
来自 MSDN 文章“如果更改 .NET Framework 版本,如果您的代码包含对不同版本的引用,则可能会收到错误消息。”
此处提供了精彩的 MSDN 演练:http://msdn.microsoft.com/en-us/library/bb398202.aspx
如果您想强制执行版本2.0 在构建服务器上,然后修改 msbuild 选项以将工具集版本“覆盖”为 2.0。此命令开关优先于项目设置文件,并且“导致所有项目及其项目到项目的依赖项根据该 ToolsVersion 进行构建,即使解决方案中的每个项目都指定了自己的项目”。以下是有关工具集的 msdn:http: //msdn.microsoft.com/en-us/library/bb383796(v=vs.90).aspx 以下是有关如何指定命令行开关的 MSDN:http://msdn.microsoft.com/en-us/ library/bb383985(v=vs.90).aspx
如果您使用 TFS 进行夜间构建,那么这里是如何添加参数(我正在使用 VS 2010 Pro):
现在,即使项目文件发生更改,构建服务器也会捕获 2.0 级别以上的代码并失败。如果您不使用 TFS 进行构建,请查看您的工具是否允许您修改 msbuild 命令行。
It sounds like you want to change the "Target Framework" of the project(s) in question to .Net Framework 2.0.
From the MSDN article "If you change the .NET Framework version, you may receive error messages if your code contains references to a different version. "
Great MSDN walk-through here: http://msdn.microsoft.com/en-us/library/bb398202.aspx
If you want to enforce version 2.0 on the build server, then modify the msbuild options to "override" the toolset version to 2.0. This command switch takes precedent over the project settings file, and "causes all projects and their project-to-project dependencies to be built according to that ToolsVersion, even if each project in the solution specifies its own". Here is the msdn on what a toolset is: http://msdn.microsoft.com/en-us/library/bb383796(v=vs.90).aspx and here is the MSDN on how to specify the command line switch: http://msdn.microsoft.com/en-us/library/bb383985(v=vs.90).aspx
If you are using TFS to do your nightly builds then here is how to add the argument (i'm using VS 2010 Pro):
Now, even if the project file changes the build server will catch code above the 2.0 level and fail. If you are not using TFS to do the builds, see if your tool lets you modify the msbuild command line.