Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to #define CONSTANT on a solution basis? [duplicate]

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

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?

like image 421
Graviton Avatar asked Mar 11 '11 02:03

Graviton


People also ask

Is there anyway or any way?

Which word is it, anyway? Anyway is a common adverb used to mean “in any case,” while any way is an adjective-noun phrase that means “whichever path” or “in any manner.” Anyways is the informal form of anyway. While less common in formal writing, anyways abounds in everyday speech or dialogue.

How do you use anyway in a sentence?

Examples of anyway in a SentenceThe road got worse, but they kept going anyway. I didn't expect her to say “yes,” but I asked her anyway. It makes no difference what we say. She's going to do what she wants anyway.

Is anyways correct English?

Anyways is a real word and has seen use meaning "in any manner or respect" for over 800 years.

Can I start a sentence with anyway?

Anyway is a common adverb that you will hear in everyday speech. Like many other adverbs, it can appear at the beginning, middle, and end of a sentence.


2 Answers

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> 

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/

like image 165
Ade Miller Avatar answered Sep 21 '22 11:09

Ade Miller


I have another approach for doing this:

  1. Edit global config file. For example in my case it's .netcf2.0 so it's $(MSBuildBinPath)\microsoft.compactframework.csharp.targets.

    Add the following line:

    <Import Project="$(SolutionDir)CommonSettings.targets" Condition="exists('$(SolutionDir)CommonSettings.targets')" /> 

    This is to tell MSBuild import the CommonSettings.targets if it's existed in your solution folder.

  2. Create CommonSettings.targets under your solution folder.

    For example to define ABC symbol:

    <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">     <PropertyGroup>     <DefineConstants>$(DefineConstants);ABC</DefineConstants>     </PropertyGroup> </Project> 
like image 36
Tim Chan Yiu Man Avatar answered Sep 20 '22 11:09

Tim Chan Yiu Man