开发者

Forcing the build to fail if there is a .net version mismatch

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开发者_如何学JAVA the build". Is this possible/the best way to do this?


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):

  1. Go to Team Explorer and expand the project
  2. Right click the builds item
  3. Select New Build Definition (or edit an existing build definition)
  4. Go to Process
  5. Expand "Agent Settings"
  6. Find MsBuild Arguments.
  7. Add /tv:2.0 and save the build changes when you have finished with any other settings.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜