Conditional Build to use Project reference or Package reference

BAYART, TONY 0 Reputation points
2023-04-05T09:16:20.2066667+00:00

I have a dependency project called MySDK used in more than one project. MySDK is published as a Nuget package in my Azure DevOps organisation. I have a ServiceApp referencing MySDK as a Nuget package. ServiceApp is also build in my Azure DevOps organisation. To upgrade MySDK in a easier way, i wanted to have the project inside the ServiceApp solution. So i referenced MySDK as a git submodule and added the project to the solution. The csproj of ServiceApp referencing MySDK was

    <ItemGroug>
      <PackageReference Include="MySDK" Version="1.0.7446.15201" />
    </ItemGroup>

Then i updated it to add conditional referencing

    <PropertyGroup>
      <TargetFramework>net6.0</TargetFramework>
      <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
      <PublishDir>$(SolutionDir)publish\</PublishDir>
      <UseNugetSDK>True</UseNugetSDK>
     </PropertyGroup>
     <!--Disable Nuget SDK when Configuration is NOT Release and NOT building under DevOps pipeline-->
     <PropertyGroup Condition="'$(Configuration)'!='Release' And '$(TF_BUILD)'!='True'">
       <UseNugetSDK>False</UseNugetSDK>
     </PropertyGroup>
     <ItemGroup Condition="'$(UseNugetSDK)'=='True'">
       <PackageReference Include="MySDK" Version="1.0.7446.15201" />
     </ItemGroup>
     <ItemGroup Condition="'$(UseNugetSDK)'=='False'">
       <ProjectReference Include="..\Submodules\MySDK\MySDK\MySDK.csproj" />
     </ItemGroup>

Building the solution always use the package reference, never the project reference. I tried also to use a Choose block this way

    <Choose>
      <When Condition="'$(UseNugetSDK)'=='True'">
        <ItemGroup>
          <PackageReference Include="MySDK" Version="1.0.7446.15201" />
        </ItemGroup>
      </When>
      <Otherwise>
        <ItemGroup>
          <ProjectReference Include="..\Submodules\MySDK\MySDK\MySDK.csproj" />
        </ItemGroup>
      </Otherwise>
    </Choose>

but this is not working better. What i missed to make this working ?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,531 questions
{count} votes