How to explain the differences in these nested Visual Studio projects? - c#

I am new to .Net and Visual Studio. In order to learn more, I decided to create a simple asp.Net application in my spare time. In Visual Studio I am trying to follow the same project structure as the application I support at work. I noticed that my work application has the following project structure
Development
|_services
|_RedSun.Onvia
|_various VS project folders (i.e. RedSun.Onvia.Core, RedSun.Onvia.Web, etc)
|_RedSun.Onvia.sln
|_RedSun.Onvia.v12.suo
Notice how the VS solution files are on the same level as the RedSun.Onvia solution folder. However when I create a basic empty project Visual Studio, it gives me the following structure...
Development
|_services
|_RedSun.Onvia
|_RedSun.Onvia.sln
|_RedSun.Onvia.v12.suo
Note the RedSun.Onvia.sln and RedSun.Onvia.v12.suo files are a directory deeper than the solution folder. When I tried moving files around manually with File Explorer to try and match the structure above I was unable to open the project in VS due to errors.
Can anyone please explain how I can get the same structure as shown in the first example?

Related

Is it safe to edit .csproj file in Visual Studio 2019?

We have a C# solution with multiple projects. We are managing version control for the solution using Github desktop, i.e., outside Visual Studio. After pushing new code to GitHub on a new machine with a fresh install of Visual Studio 2019 community edition, when I add a new file to the API project in the solution, I find that the file gets added to the .csproj file as follows, and the IDE never includes the file in the build, debugging, code completion etc.
<ItemGroup>
<Compile Remove="Controllers\TestController.cs" />
</ItemGroup>
I also see a + sign next to the TestController file in Solution Explorer. Hovering over the + sign brings up the message "pending add."
Why is this happening? And is it safe to just remove this itemgroup block in the .csproj file? Is there a way to prevent this behavior for new files added to the project?
Details
Context:
C# solution with 5 projects - (1) WebAPI, (2) Identity, (3) DataAccess, (4) Services, (5) Shared libraries. Editing using Visual Studio 2019 Community Edition.
Full timeline:
Solution pulled from GitHub.com using GitHub desktop
Files added to DataAccess and Services project using Visual Studio. Everything was fine
New branch created in GitHub desktop. New files added to the branch using GitHub desktop and pushed to GitHub.com using GitHub desktop
Code merged with parent branch by project administrator
Local solution synced to remote repository using GitHub desktop
--- alert: problem seen now ---
New file (TestController) added to the API project using Visual Studio. This file does not become part of the build. IDE does not highlight ApiControllers, ControllerBase etc, does not indicate errors for mis-spelt services, pressing F11 on ApiControllers gives error message "cannot navigate to the symbol under the caret."
Google search suggests checking on .csproj file. Here I find that the new file is within the 'compile remove' block.
Is it safe to edit .csproj file in Visual Studio 2019?
If you know what you're doing and you do it correctly, sure. Otherwise, not so much.
Why is this happening? And is it safe to just remove this itemgroup block in the .csproj file? Is there a way to prevent this behavior for new files added to the project?
It's happening because a file showed up in the project subdirectory that Visual Studio doesn't have as part of that project. So it adds the <Compile Remove... /> element to exclude it from being compiled as part of the project. It is safe to remove the element, but in my experience it just shows up again.
As a general rule, you should not be adding files to project directories managed by Visual Studio, except by using the Visual Studio UI itself. It's not clear from your post why you are doing this. The directory you apparently are adding files to is your project directory. It should only have files that do in fact belong to the project.
The best fix is to not try to add files to a project directory when they shouldn't be part of that project.
You may have an XY Problem. If you can post a new question in which you explain the scenario in which you've added the files that don't belong, and ask for guidance to accomplish whatever broader goal it is you have, but without running afoul of Visual Studio's rules, you may get a better answer than "don't do that".
I think I have identified the problem. I believe what happened is that once the local branch was pushed to remote, further changes to the project made using Visual Studio were not being integrated into the project, even though I was not formally tracking the project in Visual Studio.
git status showed that I was still on my initial local branch. I did the following to sync with the remote parent branch and then start a new local branch:
git stash
git checkout <parent_branch>
git pull
git checkout -b <new_branch>
This switched me to a new branch, and now I am able to edit the file as usual.

opening c# files with visual studio outside of project gives no suggestions

Im currently writing some very small c# exercises, for a algorithm course.
visual studio is my favourite IDE, and usually, when i create or clone a visual studio project, I get the full functionality of viusal studio including spellchecking and suggestions for fields and methods on objects and so on.
But right now I am just trying to open a single .csc file and write some code in it. The problem is that when i do that, i get no suggestions. So if I create a list I would usually be able to view all the methods and fields inside the list class simply be referencing an object. Syntaxm checking works fine.
How do I turn on intellisense suggestions in a file that is not in a project?
Thank you
The simplest way is simply to add that file to a project.
Open VisualStudio.
Create a new project (you can probably use Console project or Class library, depending on what you're doing).
Add your file in that project.
Make sure your file as the Build Action C# Compiler.
And that should work.

Cannot create .apk file after introducing Crypto Obfuscator into Xamarin.Android project

I have a task of obfuscating my Xamarin Android project (let call it AndrProj) together with libraries it references: two PCL (let's call them PCL1 and PCL2) and Android library (AndrLib). PCL2 and AndrLib also have references to PCL1.
I was inspired by this article and decided to try Crypto Obfuscator For .Net v2015 demo version for my purposes.
I used its 'Visual Studio Project Integration Wizard'. PCL1 was set as 'First project' and AndrProj as 'Last project'. Only default settings were used for the beginning. Now when I build my project everything is perfect. Dll's in \bin\Release folder are obfuscated.
I would be completely happy if I could actually create an .apk file and try it on the Android device. But when I select Build -> Archive for Publishing in Xamarin Studio, after some time I see 'Build FAILED' and
Error occurred while obfuscation: - The assembly 'AndrLib' is
already obfuscated with Crypto Obfuscator. If you have run the Visual Studio Project Integration Wizard on your Visual Studio projects, you cannot obfuscate from the Crypto Obfuscator UI unless you first disable automatic obfuscation for this project from Crypto Obfuscator's 'Project' menu --> 'Enable/Disable Visual
Studio Integration' and Rebuild your solution in Visual Studio to
produce unobfuscated assemblies.
I also tried 'Export Android Package (.apk)' from Visual Studio 2013, but it gives less output and still does not create .apk.
I believe it complains only about AndrLib because it goes first alphabetically among PCL1, PCL2 and AndrLib. And more global problem is that creating .apk forces all assemblies to be obfuscated one more time. Is there any way to skip this second time obfuscation? Or to ignore this kind of problem?
Well, the solutions was pretty simple: I had to use MSBuild.exe directly with target SignAndroidPackage instead of creating .apk from IDE.
Here is an email from technical support regarding the described problem (may be useful for someone):
If your solution fails to build after doing MSBuild Integration, try the following:
Change the build output log verbosity as follows:
Visual Studio Tools menu --> Options --> Projects And Solutions --> Build and Run --> MSBuild Project Build Output Verbosity, set this to Detailed.
Now check the Visual Studio Output window for any hints or more information regarding the cause of the error.
Change the number of threads used by MSBuild to 1 as follows:
Visual Studio Tools menu --> Options --> Project And Solutions --> Build And Run --> Maximum number of parallel threads : set this to 1.
If you get an error message similar to "The assembly 'XYZ' is already obfuscated with Crypto Obfuscator..." when you Run (CTRL+F5) or Debug (F5) your solution, then try doing a Clean ( Visual Studio Build menu --> Clean menu item) and then do the Run (CTRL+F5) or Debug (F5).
Build failure can also occur if you ran the wizard multiple times, each time selecting a different "first" project. This problem usually presents itself via a "file not found" error in the build log/output. To solve this problem, start from clean non-integrated .csproj/.vbproj files (the wizard copies the original non-integrated project files to a .backup_%timestamp% extension before modifying the project files; alternately you can open the .csproj/.vbproj files in a text editor and remove the XML added by the wizard which can be found towards the end of the file). Then run the wizard again specifying the correct first and last projects.
I had problems Archiving and the problem went away after I downgraded Visual Studio 2017 Professional from 15.9.9 to 15.7.6.

Visual Studio 2008 adding incorrect working folders to TFS Workspace

I am using Visual Studio 2008 with TFS. I have one workspace set up with one working folder. I map the root source control folder $/ to C:\TFS and get all code. When working on any project under the root, Visual Studio will randomly add incorrectly mapped working folders to my workspace.
For example, it might map $/WebProject/ to C:\TFS\WebProject\DataAccess -- where the real files exist at C:\TFS\WebProject.
Once it incorrectly adds these working folders, I can no longer open the solution. I am forced to remove the working folders that Visual Studio added and get latest from TFS.
Has anyone experienced this? Is there something I can do to avoid running into this?
go to "Source Control Explorer". Click on the "Workspace" dropdown. Select "Workspaces" and delete any custom workspaces you don't need.
Update:
Your vs2008 TFS cache might be corrupt. Your cache is located here:
C:\Users\YourUserName\AppData\Local\Microsoft\Team Foundation\1.0\Cache
Install Team Foundation Sidekick and look at your workspaces
http://www.attrice.info/cm/tfs/
http://www.attrice.info/images/workspace_sk_screen.gif
What do you see there?

Issues with intellisense, references, and builds in Visual Studio 2008

Hoping you can help me -- the strangest thing seems to have happened with my VS install.
System config: Windows 7 Pro x64, Visual Studio 2008 SP1, C#, ASP.NET 3.5.
I have two web site projects in a solution. I am referencing NUnit / NHibernate (did this by right-clicking on the project and selecting "Add Reference". I've done this for several projects in the past).
Things were working fine but recently stopped working and I can't figure out why. Intellisense completely disappears for any files in my App_Code directory, and none of the references are recognized (they are recognized by any file in the root directory of the web site project.
Additionally, pretty simple commands like the following (in Page_Load) fail (assume TextBox1 is definitely an element on the page):
if (Page.IsPostBack)
{
str test1;
test1 = TextBox1.Text;
}
It says that all the page elements are null or that it can't access them.
At first I thought it was me, but due to the combination of issues, it seems to be Visual Studio itself.
I've tried clearing the temp directories & rebuilding the solution. I've also tried tools --> options --> text editor settings to ensure intellisense is turned on.
I'd appreciate any help you can give!
If you think it is VS then try running it with this command line to get it back to factory defaults: devenv /resetsettings
Alternatively you may be experiencing issues due to the fact that intellisense only works on code that is (pre)compiled check the following:
a required folder is marked as excluded,
there is an issue compiling a referenced project.
compile error in the global.asax class. Note: extra { or } in a class bubbles from the root folder, usually kills intellisense. (Clean solution then build watch output for error's)

Categories