Change file full path in a C# project in Visual studio 2012

.net, c#, visual-studio

Solution

To expand on @TheSolution's answer:

- File > New Project (or Solution > Right-click > Add New Project) > Class Library -- name it something like "MyProject.Common"

- Add Existing Files (Shift+Alt+A) to project > choose files to share. Or copy/paste

- Delete old files in original project, as they've been copied to the shared project

- Then in the projects in which you want to use the common files, Project > Add Reference > Choose from under "Solution > Projects" in left panel, check the "Common" project and choose "OK"

- Include the namespace in the `using` section at the top of the code files which use the common code.

If you're talking about renaming a C# project and its folder, you have to do this manually in the `.sln` and `.csproj` files after renaming the project in the solution. ex) If you want to rename "ME.MyProject" to "ME.YourProject":

- Project > Properties (ALT+ENTER on project in Solution Explorer)

- Change both "Assembly name" and "Default namespace"

- Close VS (or unload solution)

- Rename folder

- Open `.sln` file in a text-editor and follow the manual steps below

- Open the `.csproj` files of all other projects referencing this one and change references from "MyProject" to "YourProject". Alternatively, delete and re-add project references within VS.

`.sln`:

BEFORE:

Note that the project file has been renamed, but not the path.

Project("{SOMEGUID}") = "ME.YourProject", "ME.MyProject\ME.YourProject.csproj", "{ANOTHERGUID}"
EndProject

AFTER:

Project("{SOMEGUID}") = "ME.YourProject", "ME.YourProject\ME.YourProject.csproj", "{ANOTHERGUID}"
EndProject

`.csproj`:

BEFORE:

<ProjectReference Include="..\ME.MyProject\ME.YourProject.csproj">
  <Project>{ANOTHERGUID}</Project>
  <Name>ME.YourProject</Name>
</ProjectReference>

AFTER:

<ProjectReference Include="..\ME.YourProject\ME.YourProject.csproj">
  <Project>{ANOTHERGUID}</Project>
  <Name>ME.YourProject</Name>
</ProjectReference>

Problem

In your opinion , it would be possible to change a file full path in a C# project, In Visual Studio 2012?? I ask this because in visualization, the properties box for a project file that contains full path appears as disable ( gray). I would use the same file in different project, under the same solution, without duplicate file code .cs.

Original source

Related problems