0

I want to provide variables for common path in hint path in .cspoj after installing nuget package. Example:

  1. After installing myNuget package in cs poject, few deliverables are added to project reference.
  2. Unload the project, and edit the .csproj.
  3. observe the deliverable hint path : ..\packages\myNuget1.0.0\lib\net46\sample.dll

Here instead of ..\packages\myNuget1.0.0\lib\net46\sample.dll path I want it as $(MyDLLSPath)\sample.dll.

I have no idea how to create these varibles. I have .nuspec, .props, .targets and .nupkg file.

I'm trying to create properties for paths in .targets file see below, but still issue is not resolved:


<?xml version="1.0" encoding="utf-8"?>
<Project
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  
   <PropertyGroup>
    <UserTargetsPath>$(MSBuildProjectFullPath).user</UserTargetsPath> 
  </PropertyGroup>
  
   <PropertyGroup>
    <SDKInstallPath Condition=" '$(SDKInstallPath)' == ''">$(MSBuildThisFileDirectory)..\lib\net46</SDKInstallPath>
    <SetupPath>$(SDKInstallPath)\Sample.dll</SetupPath>
    <SDKExtDir Condition=" '$(SDKExtDir)' == ''">$(SDKInstallPath)</SDKExtDir>
  </PropertyGroup>
  
 <UsingTask TaskName="ResolveReferences" AssemblyFile="$(SDKInstallPath)\Intergraph.Setup.dll"/>
 
 <ItemGroup>
    <MyExtension Include="$(MyExtension)"  Condition=" '$(MyExtension)' != '' " />
  </ItemGroup>
  
<PropertyGroup>
    <ResolveMyExtensionReferencesDependsOn>
      PrepareForBuild
    </ResolveMyExtensionReferencesDependsOn>
  </PropertyGroup>
  
  
  <Target
    Name="ResolveMyExtensionReferences"
    DependsOnTargets="$(ResolveMyExtensionReferencesDependsOn)"
    Condition=" '@(MyExtension)' != ''">

 
    <CreateProperty Condition=" '$(MyExtensionSearchPaths)' == '' " Value="
      $(ReferencePaths);
      {HintPathFromItem};
      {RawFileName};
      $(SDKExtDir)
      ">
      <Output TaskParameter="Value" PropertyName="MyExtensionSearchPaths" />
    </CreateProperty>

    <ResolveReferences
      MyReferences="@(MyExtension)"
      SearchPaths="$(MyExtensionSearchPaths)"
      SearchFilenameExtensions=".dll">
      <Output TaskParameter="ResolvedMyReferences" ItemName="_AllResolvedMyExtensionPaths" />
    </ResolveReferences>

    <!-- Remove duplicate extension items that would cause build errors -->
    <RemoveDuplicates Inputs="@(_AllResolvedMyExtensionPaths)">
      <Output TaskParameter="Filtered" ItemName="_ResolvedMyExtensionPaths" />
    </RemoveDuplicates>
  </Target>

</Project>

Thanks in advance!

Kalyani Reddy
  • 131
  • 10
  • The new [PackageReference format](https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files) which replaces `packages.config` for most projects no longer modifies the csproj and thus doesn't add the hint to it. Maybe migrate away from `packages.config` to fix issues you may have (source control?) with in-box tools. – Martin Ullrich Apr 06 '21 at 12:06
  • @MartinUllrich I had created new properties to resolve reference paths in .targets file. I have updated the post above. Please suggest where I had done wrong. – Kalyani Reddy Apr 06 '21 at 13:59
  • At this point I suspect this may be an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Please describe why you need this - esp. since NuGet should do all dependency management and MSBuild all assembly resolution. From the update it also seems you are writing a task. – Martin Ullrich Apr 06 '21 at 14:11
  • @MartinUllrich what I really want is: After installing mynuget package, dependencies will be added to project reference and if we observe HintPath for my dependencies it will be added like this: ..\packages\myNuget1.0.0\lib\net46\sample.dll. I want it display hint path as $(MyDLLSPath)\sample.dll by creating new vaiables MyDLLSPath with value ..\packages\myNuget1.0.0\lib\net46. Please suggest how to do it – Kalyani Reddy Apr 07 '21 at 13:28
  • as this is managed by NuGet, i strongly recommend not trying to edit this yourself or switch to `PackageReference` where the csproj file does not contain the direct references to the dll files – Martin Ullrich Apr 07 '21 at 14:47

0 Answers0