Get the StartUp Project of the current sln file on building - visual-studio-2010

Some of my projects have behavior based on the settings of the startup project. I.e. copy the resource to some other directory etc.
How can I get the reference to the startup project (the path to the folder would be also enough) on buildig of a project inside VS 2010?
Regards,
Andrey

Go to TOOLS
Select OPTIONS
Then Start UP
Also check that Detect when file is changed outside of environment.
You need to start every new project from a blank project. If a current project is open, there should be an option to close it before creating or opening another project. It's important not to mix up files from different projects.

Related

In TFS, can I bind a file in another folder to a Project?

I have a TFS project at $/src/main/MyProject/MyProject.csproj
It has a reference to a DLL at $/dependencies/dependency.dll.
The way I want things to work is that when my colleagues get MyProject, or open it in Visual Studio, I want TFS to go get the latest dependency.dll as well.
(In a similar way, I've actually bound MyProject to my solution in $/src/main/MySolution/MySolution.sln. So if a user gets MySolution and opens MySolution.sln then Visual Studio will go get MyProject as well. I just want to extend this to the next level, that of binding a file to a project.)
This is the perfect scenario to make use of NUGET and even though a little additional work, I would rather go this route :)
Now if you dont want to create the Nupkg etc, one easy way out is to make use of the VisualStudio Add link option.
"Add Link" is project specific and it will add a new entry to your project file specifying the location of your CS/Js/Dll etc file. As long as the file is available in the particular location TFS/VS will pull the latest copy of that file while opening the solution in VisualStudio. Make sure that the Add link creates a relative path to the file and not an absolute path.
ADD vs ADD link
Have you seen the recent announcement on package management for Team Services?

How can I change the default build output directory in Visual Studio?

In Visual Studio 2010 through 2013, by default (eg. When I create a new Console Application) new solutions output their compiled executable into Solution name/Project name/bin/Debug/. I want them to be output into Solution name/Debug/, and likewise for all other build configurations like "Release".
I can do this by manually going into properties of each project, going to the Build tab, changing Output path from bin\Debug to ..\Debug. I must repeat this for every project and every build configuration.
After dozens of solutions, I'm a bit sick of doing this tedious task by hand every time. Is there a way to change the default output path?
A solution that works for Visual Studio 2013 is sufficient.
This property is defined in each Visual Studio Project Template
So, for example, the C# Console Application template is located in
\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ProjectTemplates\CSharp\Windows\1033\ConsoleApplication\consoleapplication.csproj
The csproj is an XML file that you can edit at your will. The build output directory is define like this (for each configuration):
...
<OutputPath>bin\Debug\</OutputPath>
...
<OutputPath>bin\Release\</OutputPath>
...
If you change this file, it will change all your future new C# Console Application projects. You could also write a utility program that list all csproj in \Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ProjectTemplates and update them accordingly.
This is not necessary.
One of the projects in your solution is marked as the Startup project, shown in bold in the Solution Explorer window. An EXE project, like your console mode app. You used Project + Add Reference to add references to other projects in the solution so you can use the class libraries that those projects generate in your console mode app.
Those references will have the Copy Local property set to True.
When you build your project, MSBuild will automatically copy the assemblies from their respective bin\Debug directory into the bin\Debug directory of your console mode app, thanks to that Copy Local setting. And it is smart enough to also look at the dependencies of those class libraries and copy them as well.
So after the build is complete, the bin\Debug directory won't just have your console mode project's EXE file but also all the DLLs it needs to execute properly.
There are a few ways that this can go wrong and MSBuild cannot figure out that such a dependency actually exists. Pretty uncommon, you'd for example have to use Reflection in your code to load assemblies (Assembly.Load() and friends). The workaround for that is to explicitly copy the dependency in a post-build event. You didn't leave enough bread-crumbs in your question to judge whether that's the real problem.
What you ask for is certainly possible, the IDE just doesn't make it easy because it wasn't designed to assume this was necessary at all. You'd have to replace the Build + Output Path setting to, say, ..\Debug instead. You can create your own project template with that setting already preset. Create a new class library project, change the setting and use File + Export Template to create the template. You'll have it available the next time you create a project.
But, really, find out first why the default Copy Local machinery isn't working for you.
Rather than changing a global, protected file, you can create your own .targets file that changes the <OutputPath> however you want and import that into your projects. This could also set other defaults you might want to change and don't want to do for every project. All you'd have to do then in your project files is add something like toward the top (after the root element, of course):
<Import Project="$(SolutionDir)\Common.targets"/>

Opening a Visual Studio 2010 project in 2012 what creates the backup folder and how to control it?

I have an issue. We are upgrading to VS 2012 at work. When we open a VS 2010 project Visual Studio converts the project. This is fine, because VS 2010 can still use the project (yay microsoft). However, there is a \Backup folder created in the solution directory. Is this being created as part of the migration? Is there any way to control it?
The reason I ask is that the process that makes this folder copies web.config files into the folder. If you then try to build the solution (these are MVC projects), we get a "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS." error. The cause is that there is a web.config file in a subfolder instead of the root folder. We did not make and do not want this change, and cannot figure out how to control it. Deleting the Backup\Web.config file fixes the error. Renaming it from web.config to web.config.bak fixes the problem.
I don't really want to have to personally open and convert every single project, and don't want random people bumping into this problem. Any idea how to either stop VS from creating the Backup folder, or how to make it create them in the my documents studio folder etc? I can't find any setting to control this and can't find any good info.
By chance, are you using the MvcBuildViews property to pre-compile your views at build time? If so, this is why you're encountering this (since it does the pre-compile in the same directory, it doesn't filter out any of the files below the project directory).
Note that you will also encounter this issue if you use the Publish feature for this project. Publish copies the web.config under your intermediate build output directory (by default, obj/) before and after applying web.config transforms.
The good news is that in VS2012, or in VS2010 with the latest Azure SDK installed, pre-compile is now supported for Web Application Projects (including MVC). These settings are currently in the project properties, under the Package/Publish Web tab.
(this doesn't directly address your question about the Backup folder, but it was too long for a comment.)
There is no way to control it that I found. We had to go ahead and run through and convert every project to 2012 and delete the backup folders to prevent any other team from running into it.

Is it possible to specify a sources folder in a Visual Studio project?

I am comming from the Java world where I usually worked with Eclipse and IntelliJ. Both IDE's allowed one to specify a folder in the project directory to be the root folder for my sources. Typically this was a folder named "src" or "source". In Visual Studio 2010 I found an option on the 'Build' tab of the project properties screen that allows me to change the output directory but I was not able to find something for the 'input' directory. Is it possible to define such an 'input' directory?
You can simply add directories into your project. Open up the project in Visual Studio -> Right click on the project -> Add -> New Folder.
You can also link files into the project while they reside elsewhere.
Besides that, using those directories is quite uncommon in .NET so you should think about adapting the common habbits of the new platform to successfully develop for the new platform. Special-purpose solutions tend to do more harm.
In visual studio you can define a "default" root for all your projects. You do so by going to Tools -> Options -> Projects and Solutions and setting the first textbox "Projects location".
After that, you should know and follow how .Net projects are arranged.
Let's say you are creating a website called "TestSite". You will have a root folder with that name, and in that folder you will have a solution file "TestSite.sln" and as many subfolders as the number of projects your solution will be made of. A common scenario could be the following:
TestSite.sln
TestSite.Bll
TestSite.Dal
TestSite.Web
That would be three projects, the first two of type "Class library" as they are your business layer and data layer, and the third of type "Web application" or "Mvc application" (which is much better).
You can reference the projects between them, and when you compile you get everything tied together.
Generally project sources is placed where the project file is.
In C++ projects you can specify include folders. In C#/VB you may edit .csproj/.vbproj file as text file and change what you want.
Also you can add existing items into project.
And read this article

Visual Studio: Set default startup project

I have a Visual Studio 2010 solution with several projects.
One of the projects is set as the default project, but I want to change that by default.
I know that I can right click the project I want to be the startup project and select "Set as StartUp project", but this setting will be stored in the user's files (.slo and .user files).
As a company policy, we don't check these files in the source control system, therefore when another user opens the solution it will have a different project as the startup object.
Is there another way to set these values? Something like a setting on the .sln or .proj files?
Thanks
From Arian Kulp's site, the way to change the default startup project for a solution is to edit the .sln file. You'll see some Project and EndProject lines. The first Project listed will be the default startup project, so just move the one you want to the top.
Follow these steps:
Choose the name of the project which you want to set default startup project
Click to the Project on toolbar and then click Set as startup project

Resources