New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace projectreferences with packagereferences #7779

Open
KrayZeee opened this Issue Feb 11, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@KrayZeee
Copy link

KrayZeee commented Feb 11, 2019

Hello, im currently setting up a buildserver, which builds a application that provides interfaces for other applications to communicate with it. I want to pack the Interfaces as nuget packages. But im stuck on a problem.

There are 3 layers:
layer 1 is depending on 2, 2 is depending on 3.
the solution in visual studio has them referenced as projectreferences, since they are build upon. referencing them as nuget is not possible, or at least i dont know how to do it without making it a pain in the ass.

my goal is to have every layer as a nuget-package, which references the dependencies as packages.
basicly i want to have one big application, which spits out multiple nuget packages with references to each other. others can import the appropiate package depending on how much they want to import, and dependencies are resolved through nuget.

since it runs on a buildserver, it has to run automated, and here im stuck.
if im using a nuspec to define the package, the versionnumber isnt getting updated, if i use -IncludeReferencedProjects the dlls are only imported into package.

so how would i tackle this problem?

NuGet v4.9.2, VS 2017, .Net-Framework 4.7

@rrelyea

This comment has been minimized.

Copy link
Contributor

rrelyea commented Feb 11, 2019

your goal is to have 2 or 3 layers generate nuget packages. that is fine.
but you also say that you don't want to use project references anymore within your own repo.

you could do both. use project references, but build nuget packages.
other consumers will use these packages via packagereference.

sound good?

@KrayZeee

This comment has been minimized.

Copy link
Author

KrayZeee commented Feb 12, 2019

the thing is, how would i automate this?
like i said, if i use the nuspec way, i would have to manually update the version of the dependency inside the nuspec, thats a nono for me. maybe im missing something.

i hope i understood you correctly.

in case you meant i should just build nuget packages, thats already done, what i want is that the dependency is correctly set up.

@rrelyea

This comment has been minimized.

Copy link
Contributor

rrelyea commented Feb 13, 2019

can you share 3 (or more if needed) small sample project files that mimic what you are trying to do...and have concrete repro steps. then i'd be happy to talk through what you are doing. And it would be much more concrete.

@KrayZeee

This comment has been minimized.

Copy link
Author

KrayZeee commented Feb 13, 2019

Example.zip
Lets say i have the uploaded Example. In there is a solution with 3 class libraries (core, extras, full).

core has no dependencies
extras has a projectreference to core
full has projectreferences to core and extras

i want to create nuget packages of these three projects, but so that projectreferences are included as packagedependency with the current assemblyversion as minimum package version requirements. version numbers can differ!(e.g. core 1.0.3, extras 1.0.1, full 1.0.6)
basicly if someone pulls the nuget package e.g. full; extras and core should be pulled as nugetpackages aswell.

manually i would so it this ways:
create nuspec for each of the projects.
add the additional packagedependecies inside the nuspec with current assemblyversion as minimum dependency.
pack+push
BUT
when doing it this way i would have to update the versionnumbers for the packagedependencies every time i get a new build.

btw im using jenkins for ci/cd

@KrayZeee

This comment has been minimized.

Copy link
Author

KrayZeee commented Feb 13, 2019

i think i found a way im kind of happy with.
after reading the docs a bit more thoroughly and a little bit of testing i found out that if you have a nuspec file with only the additional dependencies and then use the pack command against the csproj nuget will build a package from the csproj and add the additional packagedependencies from the nuspec.

before i only tried to use either the nuspec or csproj but not both at the same time.

that didnt solve my problem completely yet though. so the next step was to get the right versionnumber into the dependency. after reading more from the docs and some googling i found out that how to get the assemblyversion of a dll from commandline and pass it as a parameter to the pack command to be used inside the nuspec.
so i have now a reusable nuspecfile:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <copyright>Copyright 2019</copyright>
    <tags>Some tags</tags>
	<dependencies>
      <dependency id="PackageID" version="$PackageIDVersion$" />
    </dependencies>
  </metadata>
</package>

in combination with following batchscript:

for /F "tokens=4" %%X in ('C:\tools\filever.exe /B /A /D "%WORKSPACE%\output\PackageID.dll"') do (
  set IBCV=%%X
)

to get my desired nugetpackage.

before i only knew of -version and other cli-options.

the full script to automate this could now look like this:

nuget restore Example.sln
msbuild Example.sln
for /F "tokens=4" %%X in ('C:\tools\filever.exe /B /A /D "%WORKSPACE%\output\Extras.dll"') do (
  set IBCV=%%X
)
nuget pack "%WORKSPACE%\Extras.csproj" -prop PackageIDVersion=%IBCV% -OutputDirectory "%WORKSPACE%\nugetoutput"
nuget push %WORKSPACE%\nugetoutput\*.nupkg

i rewrote that pretty quick for github, there might be some mistakes, but the way how i did it should be visible.

i hope this can help someone in the future

if you have tips to optimize this im happy to get feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment