1

I am working with another developer on a project. We have a class that references a file path. Both of us have different file paths that we want to point to in our computer, which has resulted in a source control war where we both keep checking in and overwriting the others file path by accident.

What is the best practice to do this? Hopefully there is some Visual studio or TFS magic?

public class FilePaths
{
    public string Path{ get; set; }


    public NLPComponentFilePaths()
    {
        Path= @"C:\Users\username\Documents\mydll.dll";


    }

}

Xander
  • 9,069
  • 14
  • 70
  • 129
  • 4
    The solution is obvious -- make those "different file paths" configurable in *your* program. – Frédéric Hamidi Jan 29 '15 at 23:06
  • 2
    exactly what paths are you referring to?! is this in relation to your application? if so - simple - have an app or web config setting configured and not checked in for your environment. – Ahmed ilyas Jan 29 '15 at 23:06
  • If the dll gets generated from another project within the solution or this file exists within the same solution folder then you can use relative path. – Bhasyakarulu Kottakota Jan 29 '15 at 23:17
  • Why not add the DLL directly into the TFS tree, in the project solution ? Can't this DLL be found on nuget ? Maybe you could use a personal nuget server ? – rducom Jan 29 '15 at 23:21
  • 1
    Why would you put a DLL at that location? If this is the same DLL you both need, it needs to be in a folder inside your solution (e.g. "References") and thus checked in along all the other files. – BCdotWEB Jan 29 '15 at 23:25
  • @BCdotNET Preferably, in NuGet. Binaries shouldn't be in source control. – Daniel Mann Jan 30 '15 at 00:23
  • @Dabiel Mann Where does this "binaries shouldn't be in source control" rule come from? If they belong to your project [they absolutely should](http://programmers.stackexchange.com/questions/110518/binaries-in-source-control), unless of course you can fetch them from Nuget. But I'm not gonna upload images or Excel templates etc. into Nuget just because they're binaries. – BCdotWEB Jan 30 '15 at 09:20

2 Answers2

2

We usually put our settings in config files with keys suffixed with the name of the developer's computer:

  <appSettings>
    <add key="Path" value="C:\somepath"/>
    <add key="Path_YOURCOMPUTERNAME" value="C:\yourpath"/>
    <add key="Path_THEIRCOMPUTERNAME" value="C:\anotherpath"/>
  </appSettings>

To read setting we use a helper class, that first checks

SomeKey + "_" + Environment.MachineName

in appSettings. If the suffixed key is not found, falls back to the actual key.

This way you can commit settings without breaking others' environment.

  • 1
    This means if there are 10 developers working on a same projects, we need to create 10 different paths in appSettings. And if more than 10 developers means many more settings. What happens when you deploy the project? Which path would you use on end-user's machine? – Kiran Varsani Jan 30 '15 at 00:20
  • You may end up with many entries in appSettings, but some developers still can agree on values. Config files are cleaned when deploying to prod, containing the actual keys only. You can allow this in debug mode only, so suffixed keys will not be used accidentally in production environment (release build). – Tamas Farkas Jan 30 '15 at 09:52
  • I guess the approach depends on developers which is different in each case. I prefer different method than what you do. – Kiran Varsani Feb 01 '15 at 05:52
-1
  1. Copy the dll file in your projects folder.
  2. Include the dll file as part of your solution/project.
  3. Right click on the dll file, click Properties.
  4. Set the the "Copy to Output Directory" property to "Copy always".
  5. Set the Path to \myDll.dll

for example,

Path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)\myDll.dll;

Here is the reference link to get base application directory.

  1. Check in your code and dll file in TFS.
  2. Get latest version on all other developer's computers.
Community
  • 1
  • 1
Kiran Varsani
  • 587
  • 5
  • 13
  • 1
    Seems a lot simpler to me to simply make it a setting in the config file. – Tim Jan 29 '15 at 23:23
  • Even if you make setting in the config file, that will be absolute path. The problem is file is located at different location on both developer's computers and they are overwriting settings of other developer. The same will happen with config file setting if relative path is used. It is better to end up at a common location which is project directory and use reference/relative location. – Kiran Varsani Jan 29 '15 at 23:27