Getting "STG_E_FILENOTFOUND" when creating project using project template wizard - c#

I am trying to create a VSIX project for creating multi-project template using Wizard but I am getting exception on
this.dte.Solution.AddFromTemplate(Path.Combine(this.templateDirectory, "WebTemplate\\UI.vstemplate"), Path.Combine(this.solutionDirectory, this.projectName), this.projectName, false);
Exception is
"could not be found. (Exception from HRESULT: 0x80030002
(STG_E_FILENOTFOUND))"
Stack trace is:
at EnvDTE.SolutionClass.AddFromTemplate(String FileName, String
Destination, String ProjectName, Boolean Exclusive)
at TemplateWizard.RootWizard.ProjectFinishedGenerating(Project project)

I struck this trying to use a project template that I had created in VS2019, to create a project in VS2022. I got around it by opening the solution in VS2019 which is still on my machine, and adding the project there.
You can unzip the template and open the template manifest to check that all the files referenced are indeed in the template. I did this, and it wasn't the problem.

Close ALL the windows as they may prevent changes.
Visual Studio has a cache for templates. This cache can be found in the link. Please delete the cache and the initial templates that were added in the ProjectTemplate folder of the visual studio folder.
I also ran these 2 commands in the Developer Command Prompt of Visual studio (probably not necessary but I tried with everything I found on the internet).
devenv /installvstemplates
devenv /updateconfiguration
Now check if you can find the templates again. They should not be there if everything was delete and the cache is clean.
Add the template again and maybe run the commands above. Now try and find the template.

Related

How to fix "Unable to remove directory 'Shared'. Access to the path 'obj\Debug\netcoreapp2.1\Razor\Pages\Shared' is denied"

I'm developing a web app using ASP.NET Core, and the Visual Studio compiler is throwing
Error MSB3231: "Unable to remove directory "Shared". Access to the
path '[Path to Visual Studio
Project]\obj\Debug\netcoreapp2.1\Razor\Pages\Shared' is denied."
The error is being thrown in an ASP.NET file, so it's not something I've done incorrectly.
I've tried manually deleting the directory and using an elevated command prompt, and neither worked. This issue had occured for me in the past, and I was able to solve it by booting into safe mode and deleting it there. The only issue with that is it's quite a pain to have to reboot my laptop twice (into safe mode and back into normal mode) when this comes up. Note that this error has come up twice already.
Under Visual Studio "solution explorer" tab
Right click your project then "Open Folder in file explorer"
Windows will open the folder , you shall see a folder name "obj" , double click and navigate into
Delete everything under "obj" , included "Debug" folder
Go back visual studio and hit "F5" debug , which will compile your project again and fix the error .
Try to go to the permissions of the folder, and give it to your user, then try again.
I don't have the fix but as a workaround, please try to see if all the projects in your solution are targeting to the same framework. I was getting the same error until I changed one of my angular project to point to .net core 3.1.

Unable to start program. [VALUE].dll is not a valid Win32 application error in Visual Studio 2017

I have developed an C#, ASP.NET web application in a Windows 7 machine using Visual Studio 2012. Now i had imported the entire project into VS 2017 running on windows 10 machine, and when i try to enter the debugging mode to analyze my code it shows the following error:
I guess the project configurations are conflicting hence it throws this error.
Any suggestions??
The same error happens when Visual Studio solution has selected the wrong Startup Project. The bold project is the designated startup project.
Go to the Solution Explorer > Right click on the correct project and select "Set as StartUp Project" in the context menu.
I also got this error. I ultimately got to know that I was not selecting .sln file.
In VS, you should select .sln file and it automatically loads the complete project structrue is what I learnt.
Selecting .sln file worked for me
These errors are mostly because you are not selecting the .sln or solution file. In your solution explorer tree, double click the solution file and then build and run.
This runs contrary to a users intuition that simply opening a file and running it would work. Consider it a poor user interface. Jet Brains Rider, for instance, does not have this issue.
Change Targeting Platforms with the Configuration Manager and Build the project then try to debug it.I hope this will help you.
Don't export the project folder. upload the .sln file.
It will work.
DLLs cannot be ran/debugged directly. You have to specify host application in the
Configuration Properties>Debugging>Command and then let it load the DLL by itself.
You will most likely need to copy the DLL to the directory searchable by the host application e.g. its root or ./plugins folder.
In the Configuration Properties>Build Events>Post-Build Event>Command Line simply enter something like:
copy "$(TargetPath)" "$(HOST_APP)\plugins"
The Startup Item needs to be a .exe file. It's looking at BusinessLayer.dll because BusinessLayer is currently the Startup Project.
First, build the solution. Then, set the Solution Explorer to folder view and find the .exe in one of you project's /bin folders. Right click on it and set it to the Startup Item.
Finally, click the play button in Visual Studio top bar.
EDIT: Basically the same as Thomas' answer, but I'm pointing out that the "correct project" is the one with the .exe file. I would have commented on his answer, but I have less than 50 rep right now.

Where usually custom build activity is downloaded when we open Process tab in Build Definition?

I have the following problem. There is a custom build process which is using the custom build activity. I've been opening this build some time ago, and everything was good. But, after some time, the custom build activity and build process has changed, got new arguments and some other changes. This activity has been updated on the server source control path, which is set in build controller settings. But, it seems that this activity doesn't want to be downloaded on my desktop, because when I open build definition, I'm getting error that my new custom type couldnot be resolved.
I've tried to build this activity by myself and place it to the folder, which contains devenv.exe, and this "solved" problem - my build process has been opened. But It is not normal.
What should I do to normally open my build definitions?
The contents of custom assembly folder defined for controller is downloaded to temp folder and loaded by studio once (im not sure if proper version increments for dlls would solve this - haven't tried) when opening the process tab on build definition. You either have dlls somewhere that overrides this (GAC, VS private assemblies) or your studio has been running for long time.
Remove the one you put along devenv, restart studio, check GAC and private assemblies, you can use Studio and attach debuger to other instance and review loaded modules this can help you pinpoint where the item is comming from.
To remove assembly run following from Visual Studio command line: gacutil /u "YourAssembly"
For studio assemblies i believe this is the folder: Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies

Can I tell Visual Studio to kindly keep its ugly meta files away from my source directory?

Short version: I want Visual Studio 2010 to save the solution and project files to the default "My Documents" directory, while regarding my actual project directory on Dropbox as the place to put source files.
I know I can "Add Existing Item" from the project menu, but that's hardly an acceptable solution as I have to manually create absolutely every file I'm to work with in VS from explorer. I've tried adding my project folder to the project, but that just resulted in VS lying to my face:
Is it possible to actually separate Visual Studio's fugly meta files from my project directory? If not, what would be the best workaround?
I might have to do my C# in Vim because of this...
NOTE: I know C++ projects has the "Add Filter" function, which appears to do almost exactly what I want, but I'm working with C#.
Workaround
Create a symlink from the actual project folder in Dropbox to Visual Studio's project folder, e.g:
C:\Users\tomas>mklink /J "...\Visual Studio 2010\Projects\Testing\Journal\journal" "...\Dropbox\Projects\cs_testing\journal"
Junction created for ...\Visual Studio 2010\Projects\Testing\Journal\journal > ...\Dropbox\Projects\cs_testing\journal
Then add the symlink to the project as an "External Item". Now Visual Studio thinks it's being devious and adding all new files to its own project directory, but they are actually ending up in my Dropbox.
Drawbacks
Every item added to the project must be put in the symlink subfolder.
Items automatically add themselves to the namespace "<project>.<subfolder>.*", so on my case an added class was automatically called Journal.journal.JournalForm.
It's tedious to do this for every project.
There are probably more, but I just discovered this workaround. I'll edit this answer later if necessary.

How to find the reason for a failed Build without any error or warning

I have a WebApplication which contains reference to WCF services.
While building using Visual Studio 2010, Build fails without any error or warning. However building the .csproj using MsBuild is successful.
Can't figure out what should I try in Visual Studio, to resolve / diagnose the issue. Can you please help out?
I find out that the build has been failing,
From text displayed in status Bar.
From output window:
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
The output tab includes configuration details.
------ Build started: Project: <projectName here> Configuration: Debug Any CPU
I noticed that if "Build + Intellisense" is selected in the Error List, it causes the error messages to be swallowed.
Change this option to "Build Only", and all error messages will be displayed:
I don't know if this is a bug in Visual Studio or what, but it certainly revealed hidden error messages that were the key to pinpointing the failure for me.
Some, like Richard J Foster, have suggested increasing the "MSBuild project build output verbosity" setting to "Diagnostic" (the highest possible option), but this didn't solve the problem for me, as Visual Studio appeared to be suppressing the error message(s) themselves.
As an alternative, you may try to use the raw output messages from the "Output" tab, which haven't been filtered by Visual Studio. Either do an in-place search for the strings "error" and/or "failed", or copy all of the output to your favorite text editor and do a search there.
To ensure that the Output window appears each time you do a build, you can go to Tools → Options → Projects and Solutions → General, and ensure that the option "Show Output Window when build starts" is checked.
As an additional troubleshooting step, it is also possible to build the project from the PowerShell command line by running dotnet build. This will show you the complete build output, including any errors that Visual Studio may be hiding.
I just ran into a similar situation. In my case, a custom action (from the MSBuildVersioning package available on Nuget.org - http://www.nuget.org/packages/MSBuildVersioning/) which appeared in the csproj file's BeforeBuild target was failing without triggering any error message in the normal place.
I was able to determine this by setting the "MSBuild project build output verbosity" (in the latest Visual Studio's Tools tab [Path: Tools > Options > Build and Run]) to "Diagnostic" as shown below. This then showed that the custom action (in my case HgVersionFile) was what had failed.
Here are some things that you can try:
If your solution contains more than one project, try building each project one at a time. (You may even want to try opening each project independently of the solution.)
If applicable, ensure that all of your projects (including dependencies and tests) target the same version of the .NET Framework. (Thanks to user764754 for this suggestion!)
Tip: Check Tools → Extension and Updates to ensure that your packages are up-to-date.
Ensure that all dependency projects are built to target the same platform as your main project.
Try restarting Visual Studio.
As suggested by Bill Yang, try running Visual Studio as Administrator, if you aren't already. (If you are already running Visual Studio as Administrator, perhaps try the opposite?)
Try restarting your computer.
Try "Rebuild All".
Run "Clean Solution", then remove your *vspscc* and *vssscc* files, restart Visual Studio, and then "Rebuild All".
As suggested by Andy, close Visual Studio, delete the .suo file, and restart Visual Studio.
As suggested by Arun Prasad E S, close Visual Studio, delete the .vs folder in your solution directory, and then re-open Visual Studio. (This folder is auto-generated by Visual Studio and contains cache, configuration settings, and more. More details can be found in these questions: Visual Studio - Deleting .vs folder and https://stackoverflow.com/q/48897191.)
As suggested by MrMalith, close Visual Studio, delete the obj folder in your solution directory, clear your temporary folder, and then re-open Visual Studio.
Delete the hidden .vs folder & restart Visual Studio. That worked for me.
I want to expand on Sasse's answer. I had to target the correct version of .NET to resolve the problem.
One project was giving me an error:
"The type or namespace name 'SomeNamespace' does not exist in the namespace 'BeforeSomeNamespace' (are you missing an assembly reference?)".
There was no error in the Error List window but the assembly had a yellow warning sign under "References".
I then saw that the referencing project targeted 4.5.1 and the referenced project 4.6.1. Changing 4.6.1 to 4.5.1 allowed the overall build to succeed.
Nothing was working for me so I deleted the .suo file, restarted VS, cleaned the projected, and then the build would work.
I tried many things like restarting Visual Studio, cleaning and rebuilding the solution, restarting the PC, etc., but none of them worked for me. I was finally able to solve the problem by doing the following:
First of all, make sure all the projects in your solution (including tests) are targeting the same .NET version. Then:
Save pending changes in the project and close Visual Studio
Find the exact location from file explorer and find "obj" file and open it,
Then, delete all the included files (some files won't remove, it doesn't matter, just skip them).
Use run command (by pressing Windows Key + R) and type "%temp%" and press enter to find temporary files.
Finally, delete them all.
On other possibility is that Visual Studio needs to run as Administrator, this might be related to deploying to local IIS server or other deployment need.
Just for the sake of completion and maybe helping someone encountering the same error again in the future, I was using Mahapps metro interface and changed the XAML of one window, but forgot to change the partial class in the code-behind. In that case, the build failed without an error or warning, and I was able to find it out by increasing the verbosity of the output from the settings:
In my case (VS 2019 v16.11.20), disabling Text Editor->C#->Advanced->Enable 'pull' diagnostics in the options solved the issue.
Double check for _underscore.aspx pages in your project.
I had a page and code-behind:
`myPage.aspx` and `myPage.aspx.vb`
when building the project, I'd get errors on the .aspx.vb page stating that properties defined on the .aspx page didn't exist, even though the page itself would build fine and there were NO OTHER ERRORS showing in the output (even with diagnostic level build output).
I then came across a page in the project that was named the same thing but with an underscore: _myPage.aspx - not sure where it came from, I deleted it, and the solution built fine.

Categories

Resources