How to get the TFS workspace directory - visual-studio-2010

I am trying to access the TFS workspace directory on my local workstation in my csproj file. I have the StyleCop files in source control and I need to add the absolute path. I created an environment variable and the does the job. I was just wondering if it was possible to get the path so my other team members would not have to do any manual configuration.

As you can have many Workspaces locally, the first thing would be to identify which workspace do you want to get the path from.
After that, using the TFS API you can easily get the local path from the server path of your csproj file.
Building a tool that create/update a sysvar can be easily written, I don't know though if it suits you.
Here's the method you should call on the MSDN: http://msdn.microsoft.com/en-us/library/bb139272.aspx

Related

How do you reference the solution folder in .targets?

I have a custom tool that I run on certain file types using the .targets mechanism in Visual Studio 2015.
Projects exist at many levels, and I want to reference this tool when the code is pulled to ANY drive/folder, including the TFS CI agent.
I tried using a relative path, but because the files are at different levels, it doesn't work for all projects.
I tried using a registry setting and environment variable, but that doesn't bode well for the CI machine which might build in a different folder each time.
Is it possible to get the solution folder of which the project/file is in, then I can use a relative path to the tool directory?
All I can find is these properties, which do not seem to help:
General MSBuild properties:
https://msdn.microsoft.com/en-us/library/bb629394.aspx
https://msdn.microsoft.com/en-us/library/ms164309.aspx
Registry and environment variables:
https://msdn.microsoft.com/en-us/library/ms171458.aspx
You can use all the standard tokens within .targets.
Just use
$(SolutionDir)
See https://msdn.microsoft.com/en-us/library/c02as0cs.aspx
Self-service answer: use visual studio's property editing for a vcxproj in preprocessor macros or include paths or such to look at a bunch of available variables. You can usually find what you need in there, by name, or by example, including the one you need here. Better than any documentation.

.partial files when checking out of TFS

When I check out a solution from TFS a get a lot of .partial-files all over the project.
They are not on the TFS-Server, just on my PC. Sadly some of them prevent my solution from running and I always have to delete them manually. Can I somehow prevent this? Where do they come from?
These files exist in the local path of your workspace but not added into source control. For the partial extension file, you can refer to this page for the meanings.
You can delete or ignore them directly. If you want to prevent it, you can also change the local path of your workspace, then you will not see the files.
Another option is creating a new workspace and using a different local path, then do a workspace mapping.

TFS 2010 Build Automation for a Web Site: Delete a file in the publish folder after build

We are trying to adapt a build automation strategy for our ASP.NET web site (not a web project) in vs 2010 ultimate & tfs 2010.
Build definition makes the build and publishes the web site into folders like
<drop_folder>\<defn_name>\<defn_name>_<year><month><day>.<build no>\Release_PublishedWebsites
Now we try to delete particular files and folders from that folder. For instance the "images" or "files" folders, that we need to exclude before packaging. I know that if it were a web project, there exists a straightforward solution. We also tried to modify the build process template (xaml) file. There is a "DeleteDirectory" component but we couldn't figure out what to write to the Directory variable.
Thank you.
If you follow the XAML way, you would just have to feed the Directory argument of DeleteDirectory with the physical UNC path to the folder you 're trying to get rid of.Something along the lines of String.Format("{0}\\{1}\\{2}\\Release_PublishedWebsites", BuildDetail.DropLocation, BuildDetail.BuildNumber, Date.Now.Year)
should get you near to your target. Since the drop location of the build might be on a different machine, also ensure that the account conducting the build (by default = NetworkService) has the rights to delete folders on the target.

Store developer-defined build parameters in Visual Studio user files?

We have different dev environments between developers here. When I build, I want my compiled files to be copied to a bin folder located in C:\Web\bin\. Another developer may want those files dropped in C:\Web_2011\bin\.
Using Visual Studio 2010, the way we work this now is to run a BAT file with the directories defined as parameters that need to be changed if pulling from another developer's branch.
Is it possible to store a solution-wide parameter, (in a .user or .suo file maybe,) to define where a developer wants to drop his builds?
You could do it through the project file (.vcxproj for C++ project for example).
The simplest solution would be to add a Custom Build Step that runs some batch file. This batch file could check the current user name and copy the files based on that.
(An even simpler solution would be to run a user specific batch file from his local disk)
If you really want the fully fledged solution that will allow you to save this data to the user file, you can do it by editing the project file and adding a PropertyPageSchema element that extends VS property pages with another parameter (your destination directory). You can define the Persistence attribute of DataSource element as "UserFile" and the data will be saved on your .user file. You will need to add some target that actually uses this data (copies files to the directory specified).
For more information, read about msbuild and PropertyPageSchema.

How should we handle .csproj and web.config with visualsvn

Context : Windows 7, VS 2010, Tortoise SVN , and VisualSVN (all up to date)
We have some problems with our web.config files and .csproj : in these files there is informations common to the whole project (like connection string, configuration element) and informations depending on the machine (mostly file path).
So the problem is, each time I commit my web.config, my colleague has to go back to his file and change the file paths.
Did you find any way to handle it ? I tried to remove these from source control but it's kind of a problem (each time someone add a file to the project we have to add it manually, or a configuration key).
Thanks
One way we've handled file paths in the web.config is through the use of symbolic links.
i.e. in the commited web.config have the files paths point to e.g. C:\website then on each developers machine run the following command:
mklink /d C:\Website c:\path\to\develper\specific\checkout
Thus no-one should need to re-edit the paths to point to their workspace.
We've not had problems with our .csproj files - they don't have machine specific config in them.
We did however have similar issues with app.config settings. Again solved by either having each developer store files in a set location or having a symbolic link from the set location to their location.
For connection strings, we've either got them all set to localhost or set them to localdatabase and have a host entry on each developers machine. This will only work if each developer connects to the same database name but on a different server. If you're connecting to the same database server but different databases, you'll need a different tactic.

Resources