Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to "override" a .csproj file setting?

I have a lot of projects in my solution.

I would like to have each of those have a setting overridden. I could just go edit them all. But that is tedious and error prone for developers that follow after me.

So, I am hoping there is a way to merge a custom .proj file into a .csproj before the build actually gets going.

The setting I want to change is the output setting (for the Debug configuration). I want to set it to $(SolutionDir)\bin\Debug.

I am a wishful thinker? or is there a way to do this?

like image 543
Vaccano Avatar asked Aug 20 '12 19:08

Vaccano


2 Answers

You could create a custom .targets file which sets the properties you want to be common for all your projects.

In your custom .targets file, set the property:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <OutputPath>$(SolutionDir)\bin\Debug</OutputPath>
</PropertyGroup>

You would still have to include this targets file in each .csproj file, as well as delete the OutputPath property previously set (otherwise, it will override the one set in your .targets file).

<Import Project="<PathToYourTargetsFile>"/>

While this does still involve editing each .csproj file, it is a bit more maintainable than directly setting that property in each file, particularly if you think there may be more settings that you want every project to have in common in the future. In any added projects, developers would have to remember to import that .targets file.

like image 189
elinor Avatar answered Nov 15 '22 11:11

elinor


Set the output parameter from the msbuild command line:

/p:OutputPath="$(SolutionDir)\bin\Debug"

OutputPath- Specifies the path to the output directory, relative to the project directory, for example, "bin\Debug".

The other option is to place a config override inside the csproj file. Like the below. Not sure if this is something you want to do though.

<Config
Name = “Release”
AllowunsafeBlocks = “false”
BaseAddress = “285212672”
CheckForOverflowUnderflow = “false”
ConfigurationoverrideFile = “debug. web. config”
DefineConstants = “TRACE”
DocumentationFile = “
DebugSymbols = “false”
FileAlignrnent = “4096”
IncrementalBuild = “false”
Optimize = “true”
OutputPath = “bin\”
RegisterForcomlnterop = “false”
RemovelntegerChecks = “false”
TreatWarningsAsErrors = “false”
WarningLevel = “4”
/>
like image 34
SoftwareCarpenter Avatar answered Nov 15 '22 11:11

SoftwareCarpenter