Tuesday, March 31, 2009 11:39 AM
kolbis
What Gives? Project Reference Vs File Reference
Just the other day, I had an argument about the way to add references to a project. As you already know, there are two main ways to achieve that:
- Project Reference.
- File Reference.
The “Project Reference”, add a reference to a project within the given solution where a "File Reference” references an assembly that is located everywhere, either on the local machine or on the network (we just browse to it and add it to the references).
So, the question is: “when to use Project and when to use File reference?”
My Opinion
In my opinion the rule should be simple:
Use “project reference” to add reference to assemblies within your solution.
Use “file reference” to add a reference to a cross solution assemblies (I will give an example later on).
An Example
Lets say that you have two teams in the development process, the infrastructures team and the application team.
The infrastructure is working on their solution. Every month they release a new version of the infrastructure and only then the application team should use the new version. In order to achieve that the application team should reference files in order to work with a specific version (release) of the infrastructures. If they would have add the project to the solution and add a reference, they would have worked on the development version that might not be ready yet.
In this case it is recommended to use “File References” and I call it “cross solution assemblies”.
Other Considerations
I assembled some pros and cons in regarding to both ways. Consider them if you are not sure which way to go:
- File reference will not allow you to see the “Go To Definition” (it will show you the metadata).
- File reference will not show you all the referenced locations in the “Show All References” option.
- Project reference sometime requires additional projects to be added as well if you have a dependency.
- With File reference you have to manually fix the build order and the dependencies.
- If you like working with multiple solutions (that are locally created), working with File References is easier.
- In project reference when ever you build your project, the referencing projects will automatically get the updated version. If you want to achieve that with file reference, you will have to add post build events.
תגים:Visual Studio, Architecture, Dev, Tips & Tricks, What Gives?