Search code examples
nuget-packagemsbuild-task

Nuget task ignore custom version of referenced projects


I'm using VS2017 and I have written a custom MSBuild SDK that create a version for each project, it does not update update project file. the version created and referenced in the SDK. This work very good for project itself and it will reflect on created nuget package from the project.
but when I reference the project from another project, and create nuget package from this second project, it will always create a dependency to version 1.0.0 of my first project.
looks like nuget pack task only look the project file itself and never run my SDK to update project version.

Now the question:

  • Is there any custom property of <ProjectReference> to indicate its version
  • Or is there any package that I can use to build nuget packages myself and insert project reference there

Solution

  • After all I find the answer by searching in NuGet.Build.Tasks.Pack.targets.

    When NuGet want to pack the project, it will call _GetProjectVersion from referenced assemblies to get their version and it depend on GetPackageVersionDependsOn.

    So the only thing that I should do, was to add the task that I use to update the version of my project to GetPackageVersionDependsOn in my Sdk.props:

    <PropertyGroup>
        <GetPackageVersionDependsOn>
            UpdateVersion;$(GetPackageVersionDependsOn)
        </GetPackageVersionDependsOn>
    </PropertyGroup>