Ikillnukes Ikillnukes - 1 month ago 7
C# Question

Compile two projects in one solution using MSBuild executable

Well, for some reason I can't compile two projects inside a solution, but one yes. In fact, now, when I start a batch file with following code it compiles one of two projects.

@echo off

::Use this in case, you haven't VS installed, or you wan't to open it!
::Maybe you need to install this, if you don't have VS 2015 or MSBuild packages: https://www.microsoft.com/en-us/download/details.aspx?id=48159

if "%MAIN_PATH%" == "" ( for %%a in ("%~dp0..") do set "MAIN_PATH=%%~fa" )
if "%REF_PATH%" == "" ( set "REF_PATH=%MAIN_PATH%\Assemblies" )

set MSBuildEmitSolution=1
msbuild "%MAIN_PATH%\Lerp2API.sln" /pp "/p:ReferencePath=%REF_PATH%" /p:Platform="Any CPU" /p:OutputPath=../Build /p:Configuration=Debug


I made this googling a little bit...

My folders:

main folder

This is the main folder where the solution is.

compile folder

This folder has the batch file I put before. And the executable of MSBuild (.NET 3.0), and its dependencies.

unity references folder

References folder, this folder contains references from Unity, needed in the compilation.

main project folder

This folder has the main project, this compiles it.

editor project folder

This folder has the part of the project that is in the editor, the folder is inside the Editor folder that you see before in the Main Project Folder.

And, when everything gets compiles this happens:

build folder

output path

This folder is the folder where the project points as you can see in the OutputPath.

The important generated files there are the Lerp2API.dll pdb and xml files. The other 3 files are only references that get copied when the compilation finishes (I want to know also how to avoid this!)

And this is the part builded from the Editor, the one that only gets compilated by using Visual Studio Build Option.

build editor path

So, my problems here, are two, the first is that I don't know how to avoid that the references get copied! And the second is that I don't know what I exaclty done before, so, if someone can explain me, what I did and how can I compile the two I one execution I will be so grateful.

Thanks!

Answer

I already fixed it! It was a simple problem with relative folder paths, putting two commands instead of one an fixing the path of the Editor project I solved it...

I wasn't realizing that the dll was compiling in other folder ^^'

@echo off

::Use this in case, you haven't VS installed, or you wan't to open it!
::Maybe you need to install this, if you don't have VS 2015 or MSBuild packages: https://www.microsoft.com/en-us/download/details.aspx?id=48159

if "%MAIN_PATH%" == "" ( for %%a in ("%~dp0..") do set "MAIN_PATH=%%~fa" )
if "%REF_PATH%" == "" ( set "REF_PATH=%MAIN_PATH%\Assemblies" )

set MSBuildEmitSolution=1
"%~dp0\msbuild.exe" "%MAIN_PATH%\Lerp2API.sln" /pp /t:Lerp2API "/p:ReferencePath=%REF_PATH%" /p:Platform="Any CPU" /p:OutputPath=../Build /p:Configuration=Debug

if exist "%MAIN_PATH%\Build\Lerp2API.dll" ( xcopy /s /z /y "%MAIN_PATH%\Build\Lerp2API.dll" "%MAIN_PATH%\Assemblies\Lerp2API.dll" )
if exist "%MAIN_PATH%\Build\Editor\Lerp2APIEditor.dll" ( xcopy /s /z /y "%MAIN_PATH%\Build\Editor\Lerp2APIEditor.dll" "%MAIN_PATH%\Assemblies\Lerp2APIEditor.dll" )

if exist "%MAIN_PATH%\Build\Lerp2APIEditor.dll" ( del "%MAIN_PATH%\Build\Lerp2APIEditor.dll" )
if exist "%MAIN_PATH%\Build\Lerp2APIEditor.pdb" ( del "%MAIN_PATH%\Build\Lerp2APIEditor.pdb" )
if exist "%MAIN_PATH%\Build\Lerp2APIEditor.xml" ( del "%MAIN_PATH%\Build\Lerp2APIEditor.xml" )
if exist "%MAIN_PATH%\Build\UnityEditor.dll" ( del "%MAIN_PATH%\Build\UnityEditor.dll" )
if exist "%MAIN_PATH%\Build\UnityEngine.dll" ( del "%MAIN_PATH%\Build\UnityEngine.dll" )
if exist "%MAIN_PATH%\Build\UnityEngine.UI.dll" ( del "%MAIN_PATH%\Build\UnityEngine.UI.dll" )

"%~dp0\msbuild.exe" "%MAIN_PATH%\Project\Editor\Editor.csproj" "/p:ReferencePath=%REF_PATH%" /p:Platform="Any CPU" /p:OutputPath=../../Build/Editor /p:Configuration=Debug

if exist "%MAIN_PATH%\Build\Editor\Lerp2API.dll" ( del "%MAIN_PATH%\Build\Editor\Lerp2API.dll" )
if exist "%MAIN_PATH%\Build\Editor\Lerp2API.pdb" ( del "%MAIN_PATH%\Build\Editor\Lerp2API.pdb" )
if exist "%MAIN_PATH%\Build\Editor\Lerp2API.xml" ( del "%MAIN_PATH%\Build\Editor\Lerp2API.xml" )
if exist "%MAIN_PATH%\Build\Editor\UnityEditor.dll" ( del "%MAIN_PATH%\Build\Editor\UnityEditor.dll" )
if exist "%MAIN_PATH%\Build\Editor\UnityEngine.dll" ( del "%MAIN_PATH%\Build\Editor\UnityEngine.dll" )
if exist "%MAIN_PATH%\Build\Editor\UnityEngine.UI.dll" ( del "%MAIN_PATH%\Build\Editor\UnityEngine.UI.dll" )

Enjoy it!

Comments