0

I am trying to change the Nu-Get package based on the debugging/release profile in visual studio 2022. This is very similar to This question however none of those solutions are working here. I created a standard console project to connect to Informix using the DB2 libs. Which runs fine. I added "docker support" through right clicking on the project in visual studio and it created a "profile" for Docker. I still have the standard Debug and Release configurations but now I have an additional drop down after the processor selection that has InformixConnect (appName), Docker, and WSL. It runs fine in Docker, which is linux, if I switch the reference manually to the linux version. I am trying to change the PackageReference value in .csproj when Docker is selected. I Tried every variation using Conditional in the linked question above, all failed to work. Any help would be appreciated.

launchsettings.json

{
  "profiles": {
    "InformixConnect": {
      "commandName": "Project",
      "commandLineArgs": "192.168.10.29"
    },
    "Docker": {
      "commandName": "Docker"
    },
    "WSL": {
      "commandName": "WSL2",
      "environmentVariables": {},
      "distributionName": ""
    }
  }
}

Top of .csproj.user

<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ActiveDebugProfile>Docker</ActiveDebugProfile>
    <_LastSelectedProfileId>C:\source\tests\InformixConnect\InformixConnect\Properties\PublishProfiles\registry.hub.docker.com_sgums.pubxml</_LastSelectedProfileId>
  </PropertyGroup>

current .csproj - I have tried numerous variations on this without success.

<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <Platforms>AnyCPU;x64</Platforms>    
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
    <PackageReference Include="Net5.IBM.Data.DB2-lnx" Version="5.0.0.500" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
    <PackageReference Include="Net5.IBM.Data.DB2" Version="5.0.0.500" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
  </ItemGroup>  
</Project>

msbuild diag output regardless of profile shows

OS = Windows_NT

The only thing I can see in the msbuild output that is changing is

ActiveDebugProfile = InformixConnect

vs

ActiveDebugProfile = Docker

Tried to run a conditional off every variation of Profile I could think of, but it didn't work. links to my different msbuild outputs if interested. console app and docker.

Updated - Feel free to download the repo and check it out. I appreciate everyone's help and would love to get this figured out.

vSteve
  • 63
  • 1
  • 1
  • 8
  • Choose/When should work. Do you have all the spaces and single quotes exactly right? – Crowcoder Apr 09 '22 at 23:15
  • This might not be really helpful, but have you tried adding -restore flag to the build? To my knowledge nuget adds build property files to obj folder that msbuild uses during build, they might still reference previous nugetpackage. – CrudaLilium Apr 09 '22 at 23:46
  • I tried the following `` with no success. – vSteve Apr 10 '22 at 11:40
  • according to this [article](https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore), restore is automatic in core. I also see it in the build window when I do rebuild. Still no success. – vSteve Apr 10 '22 at 11:43

0 Answers0