Reputation: 41
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.
Upvotes: 4
Views: 30468
Reputation: 24994
To expand on @TheSolution's answer:
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":
.sln
file in a text-editor and follow the manual steps below.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>
Upvotes: 4
Reputation: 67898
If you wanted to share a code file then you could add it as a Linked File. You can do this by right clicking on the project, selecting add existing item, finding the item in the open file dialog, and then before selecting it drop down the Open button and select the option for linked.
This will now link that code file to this project - or in other words - when it's changed in one place it's changed in both.
However, linked files are a very hacky way of providing shared functionality. The more appropriate approach is to build a Class Library with the functionality and add the DLL as a reference to the project. This means that you'll need to have a way of keeping that DLL up to date - but it's still generally more appropriate.
Upvotes: 1