0
votes

I am a beginner with MSBuild. I have a project (A) that depends on another project (B) and it consumes it either from a NuGet server either from a local workspace (I use NuGetReferenceSwitcher for this purpose). Shortly, here are my requirements:

  1. When consumed from NuGet server, project B has to support both Debug and Release builds. In this way, if we switch to Debug in Visual Studio we would be able to debug also project B when called from A. Right now, the NuGet also gives the Release version.
  2. When switching to local workspace, it should still build properly.

Here is how my local files are located:

\workspace\projectA\projectA.sln

\workspace\projectB\projectB.csproj

The solution I tried is the following:

  1. Inside projectB I created a targets file (located in build\projectB.targets) with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
    <Reference Include="lib1">
      <HintPath>"$(MSBuildProjectDirectory)\bin\$platform$\Debug\lib1.dll"</HintPath>
    </Reference>        
</ItemGroup>

  <ItemGroup Condition="'$(Configuration)' == 'Release'">
  <Reference Include="lib1">
      <HintPath>"$(MSBuildProjectDirectory)\bin\$platform$\Release\lib1.dll"</HintPath>
    </Reference>
  </ItemGroup>
</Project>
  1. projectB.csproj contains this:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="packages\some_package" Condition="Exists('packages\some_package)" />
  1. projectB.nuspec contains:

<file src="build\**" target="build\net462" />
  1. projectA.csproj (that depends on projectB) contains:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="..\packages\projectB.*\build\projectB.targets" Condition="Exists('..\packages\projectB.*\build\projectB.targets')" />
  <Import Project="..\..\..\..\projectB\projectB.csproj" Condition="!Exists('..\packages\projectB.*\build\projectB.targets')" />

Here are my questions:

  1. With this configuration, when using local workspace for projectB, the compilation of projectA fails because of the relative path of "some_package" which is not find from projectA (that also uses relative path for projectB as you see in point 4). How else could I do reference projectB from projectA so it doesn't fail the compiling?
  2. Why is this code not working to switch from release to debug when using nuget?

Thank you,

1
Could you get useful information from NightOwl888's suggestion?Leo Liu-MSFT

1 Answers

1
votes

Why is this code not working to switch from release to debug when using nuget?

Quite simply, NuGet doesn't have a concept of "Debug" or "Release".

However, there is a way to create debug symbols for NuGet packages and then configure Visual Studio to step through the code of the installed packages.