Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, February 28, 2008 3:19 PM | 1 vote
Hello,
We have a solution with both C++ and C# projects. For C++ we use output path set to something like "$(SolutionDir)..\bin\(ConfigurationName)" which works perfectly fine. We would like to use the same approach for C# projects. We build projects through IDE not msbuild.
For C# projects it turned out that VS project properties editor does not write correctly output path that includes variable paths into .csproj file. Is this a bug ??
So at first we used post-build events which worked ok with variables that copied output assembly from bin/debug to our "$(SolutionDir)..\bin\(ConfigurationName)" folder.
But then we discovered that it is possible to modify csproj file manually
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>$(SolutionDir)..\bin\(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
But some developers complain that since this is not supported by VS IDE editor we should not use this.
So let's take a step back and think about it
Let us imagine a simple example solution C:\Solution1\solution.sln
Let's initially assume
- We use default output folders for C# projects like "bin/debug"
- We cannot simply use relate paths like "../../bin/debug" because those projects are included in many different solutions on different directory levels.
1. - C:\Solution1\CPP\CPP.vcproj - C++ exe project linking to CLI library
2. - C:\Solution1\INTEROP\INTEROP.vcproj - C++/CLI library project referencing C# library 1
3. - C:\NET\LIB1\LIB1.csproj - C# library 1 referencing C# library 2
4. - C:\NET\LIB2\LIB2.csproj - C# library 2
5. - C:\NET\CS\CS.csproj - C# exe project with .config file (copy local) - referencing both C# library 1 and 2
Expected - we would like to have all exe and dll in a C:\bin\debug or C:\bin\release folders.
Since all projects are in one solution "copy local" flag does not matter, referenced assemblies are always copied.
Output result
Project 1 - C:\bin\debug\cpp.exe
Project 2 - C:\bin\debug\interop.dll and C:\bin\debug\lib1.dll
Project 3 - C:\NET\LIB1\bin\debug\lib1.dll and lib2.dll
Project 4 - C:\NET\LIB2\bin\debug\lib2.dll
Project 5 - C:\NET\CS\bin\debug\cs.exe, cs.exe.config, lib1.dll and lib2.dll
Let's debug cpp.exe. In run-time we will get error that lib2.dll is not found.
I have this sample solution, but not sure if I can attach it.
So final question is :
Which approach do you think is the best ?
- post-build events for C# projects (even more duplicate copies of assemblies and quite a mess)
- csproj manual editing (not supported by IDE editor and someone can overwrite the file by mistake)
- bogus references to all C# projects in INTEROP library to have them copied (sounds bad)
- some other approach?
Thanks,
Andrzej [severian]