none
Conditional ProjectReference?

    Question

  • Hello Folks,

    I use CruiseControl for CI. 

    Build, which I decide to do on this server are very much different from one which are in Visual Studio.

    Difference is very simple - I build one project at time.

    For a time when I build a project all referenced projects need to be substituted with relevant DLL's.

    Something like this:

      <Choose>
        <When Condition=" '$(CCNetBuildId)' == '' ">
          <ItemGroup>
            <ProjectReference Include="..\Dummy\Dummy.csproj">
              <Project>{a1cfc327-3827-43fa-910f-a65aa50fb6f3}</Project>
              <Name>Dummy</Name>
            </ProjectReference>
          </ItemGroup>
        </When>
        <Otherwise>
          <ItemGroup>
            <Reference Include="Dummy">
              <SpecificVersion>False</SpecificVersion>
              <HintPath>$(OutputPath)\Dummy.dll</HintPath>
              <Private>False</Private>
            </Reference>
          </ItemGroup>    
        </Otherwise>
      </Choose>

    However, I did a mistake and put my Dummy.dll in different folder.

    And CI did build a project.

    Investigation show that was used a ..\Dummy\obj\Dummy.dll - dll from the project excluded from the build.

    My question is - How do I prevent using a dll from places which are not included in the build?

    Best regards,

    Andrey

    Friday, December 01, 2017 12:29 PM

All replies

  • Hi Andrey Belyakov,

    Thanks for posting here.

    According to description, Visual Studio will still invoke Dummy.dll file from obj folder of Dummy project, so you can try to clean the solution before you build this project. After clean solution, the Dummy.dll will be deleted.

    Alternatively, you can add a condition to verify whether the dll exists in the build, like:

    <Reference Include="Dummy" Condition="Exists('$(OutputPath)\Dummy.dll')"> 

    https://stackoverflow.com/questions/28387596/how-to-conditionally-reference-a-dll-based-on-a-compilation-symbol

    Hope this can help you.


    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, December 04, 2017 9:09 AM
  • Hello Leo,

    May be it was not clearly described - I use a CruiseControl CI to manage a build. I do not have a solution for a build - each project are extracted from SVN into separate folder and build as project.

    I do build each project completely separately and build fully controlled - including versions of all used dlls -  by the CI.

    On the CI build a Dummy project which are referred in ProjectReference is not where it specified - it located in completely different folder and expected to not be discovered by the MsBuild.

    If Dummy.dll is not on place - it's - Ok - build suppose to fail. This result are expected and handled by CI.

    Problem is that in case when Dummy.dll missing in only place where it should to be - MsBuild do too much search for missing dll and some how find it in the Obj folder of the Dummy project. Of course there are a version which most likely is not suitable for current build. And this happen when ProjectReference are EXCLUDED by the Condition.

    I do understand your proposal to exclude a reference to the dll from build. This can be done, but this require to implement a new error handler for CI or option to send a Message from MsBuild - both are too much for me at the moment.

    Best regards,

    Andrey

    Monday, December 04, 2017 10:36 AM
  • @Andrey Belyakov, thank for your patiently explain. Since this forum is about MSBuild, I can only answer your question from MSBuild, I'm not sure if it meets your CruiseControl build requirements. If exclude a reference to the dll from build will require to implement a new error handler for CI. How about clean the IntermediateOutput, obj folder before build the project?

    To accomplish this, unload your project. Then at the very end of the project </Project>, just before the end-tag, place below scripts:

    <Target Name="BeforeBuild">
        <!-- Remove obj folder -->
        <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
        <!-- Remove bin folder -->
        <RemoveDir Directories="$(BaseOutputPath)" />
    </Target>
    Hope this helps.


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 05, 2017 8:13 AM
  • Hello Leo,

    This question are exactly about MsBuild. CI just manage to set all required part on places and call an MsBuild to build a standard project file.

    Imagine following scenario:

    - There are 2 projects - Dummy.csproj & First.csproj

    - Two separate call of MsBuild will happen - for Dummu.csproj and for First.csproj

    - In the First.csproj are conditionally reference to Dummy.csproj or to Dummy.dll as described above

    - Dummy.csproj was build successfully and Dummy.dll are in obj and bin folders of Dummy.csproj

    - CI run the Tests and Tests was failed on Dummy.dll and Dummy.dll was not copied to the place where it should be and was not provided for First.csproj build. 

    - First.csproj expected to fail on the build as Dummy.dll are not provided and reference to First.csproj are conditionally excluded .

    This is how it planned to work.

    In practice MsBuild do find and substitute Dummy.dll (which fail on the tests, are unsuitable and was NOT provided for the build) from Dummy.csproj which are EXCLUDED from the build by the Condition.

    Again:

    there are two separate run of MsBuild - one for Dummy.csproj and second for First.csproj

    on the second run of MsBuild (for First.csproj) are used a Dummy.dll which not suppose to be in use.

    Proposed cleanup for directories in the current (First,csproj) project would not have any effect on this situation - Dummy.Dll is not there - to succeed I need to cleanup a folders in Dummy.csproj in BeforeBuild of First.csproj... but Dummy.csproj already excluded from the build by the condition... and still used. 

    What can be interesting - in the build log are a record that Dummy.csproj are excluded from the build of First.csproj regards to the Condition.

    Best regards,

    Andey

    Wednesday, December 06, 2017 11:15 AM
  • @Andrey Belyakov, I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thanks for your understanding!


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 07, 2017 9:48 AM