无论如何要在解决方案的基础上#define CONSTANT? [英] Is there anyway to #define CONSTANT on a solution basis?

查看:26
本文介绍了无论如何要在解决方案的基础上#define CONSTANT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有基于 Visual Studio 解决方案的 #define Constant ?

Is There anyway to #define Constant on a Visual Studio Solution Basis?

可以在csproject的基础上定义一个常量,也可以把#define constant放在cs文件中,但是不知道vs sln是否可以定义?

One can define a constant on a csproject basis, and one can put #define constant in cs file, but I wonder whether one can define it on a vs sln basis?

推荐答案

您实际上可以使用 Ritch 方法的变体和常见的项目设置.本质上,您必须对解决方案中每个项目文件的末尾进行一次更改:

You can actually use a variation on Ritch's approach with common project settings. Essentially you have to make a single change to the end of each project file in your solution:

  <PropertyGroup Condition="'$(SolutionDir)' == '' or
                     '$(SolutionDir)' == '*undefined*'">
      <SolutionDir>....</SolutionDir>
    </PropertyGroup>
    <Import Project="$(SolutionDir)CommonSettings.targets" />
  </Project>

然后您可以定义 CommonSettings.targets 以包含解决方案范围的设置.

Then you can define CommonSettings.targets to contain the solution wide settings.

  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
           ToolsVersion="3.5">
      <PropertyGroup>
          <TacoBuild>true</TacoBuild>
      </PropertyGroup>
  </Project>

基本上就是这样,除非您想覆盖或合并每个项目中已经定义的项目设置.下面的链接详细讨论了如何执行此操作.

That's basically it unless you want to override or merge project settings already defined in each project. The link below discusses how to do this in some detail.

http://www.ademiller.com/blogs/tech/2007/12/common-project-settings-for-your-visual-studio-solution/

这篇关于无论如何要在解决方案的基础上#define CONSTANT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆