Nuget packaging multiple projects

I have noticed a few people struggle when it comes to packaging multiple projects that exist in a single solution and I had a similar problem at work. Taking a look on SO you can easily find the work-around which is to use an additional Nuget command :

-IncludeReferencedProjects

Now this works when you want to package up a project that references other projects and so on. But what if you had, lets say, 3 projects A,B and C and all 3 projects had to be packaged together? By the way, allowing them to be packaged separately just wasn’t an option.

  • Project A does not reference anything.
  • Project B references Project A
  • Project C references Project A

In this case what do we do? We want to package project A, but the above command wont work since A has no references. This means B and C wont be included.

Worry not as Nuget has us covered.

  • Got to the root directory of your solution.
  • Add a nuspec file, you can find a template pretty much anywhere.
  • Add the following lines after the metadata section
<files>
    <file src="..\src\ProjectA\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0\" />
    <file src="..\src\ProjectB\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0\" />
    <file src="..\src\ProjectC\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0\" />
</files>

All this does is tell Nuget exactly which dll’s you want packaged up. Turned out to be pretty simple in the end.

Pointers -> pointing you in the right direction;

If you are reading this then you must be looking for a simple explanation on C++ pointers or not. It is a tricky concept to grasp at first, however it looks harder than it is.

Lets take a look at a very simple example:

We can see from line 7 that we are creating a pointer i that actually points to a type int. This is what is a bit tricky to understand. A pointer is not the same type that it points to. A pointer is merely a location in memory that can be referenced by its address.

“pointer = location in memory” Remember this and you will be fine.

Back to line 7, we declare a pointer using the asterisk* . In order to access the data the pointer points to we need to use the asterisk* again. This means that if we need to change the value or read the data from the memory location pointed to by the pointer we simply need to dereference the pointer using the asterisk.

A quick recap:

  • line 7 we use the asterisk to declare the pointer
  • line 9 we use the asterisk to dereference the pointer and assign a value
  • line 11 we use the asterisk to dereference the pointer to obtain the value it points to.

Now some of you may be thinking “surely standard data types must have an address in memory as well?” and the answer to that is yes they do. We can access the location of a variable using the “&” operator. Consider the following code:

Line 7: declare variable of type int

Line 9: declare pointer that will point to a memory location with data type int

Line 11: we assign ptr with the address of x using the & operator. (careful here we are NOT assigning the value of x but rather the address of x)

Note: Be careful when applying this method as pointing to the address of a variable that has gone out of scope will lead to your program not running as expected. If a variable goes out of scope its memory address will still have a value stored there, thus your program may seem to operate OK until that memory address is used by something else in which case the value stored there will be overwritten.

There you have it, pointers put simply.

Photo by Hello I’m Nik