ASP.Net Core doesn't find cshtml - asp.net

UPDATED
I refactored the entire question, because now, I Know what are happening, Thx to Daboul
When I start the ASP.Net Core exe inside the VS15 or even on a cmd line with dotnet run it's work fine, but when I try to double click on the exe to run, it's doesn't find the .cshtml.
The weird part, is that the files are there, and are found when executed by vs15
Can someone explain to me what I'm doing wrong?
I just create an Asp.net Core Web App and changed the project.json to produce the .exe like here and here

Visual Studio and dotnet run run your application in the folder where your code exist. It means it can access the Views folder and the .cshtml files you are editing when you are coding.
However when your run your .exe application, you do it from the publication folder, for exemple ...\Visual Studio 2015\Projects\MySolution\src\MyProject\bin\Debug\netcoreapp1.0\publish I would advice you to go to this folder and check that the folder Views exist. If it does not, it means you just need to publish your views by adding "**/*.cshtml" in your project.json:
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml"
]
}
Then publish again with dotnet publish or your previous method. It should fix your problem.
Just for knowledge: It is now possible to precompile all the views with .NET Core 1.1. It means there would be no need to publish the .cshtml files.

You can see that one is running in development (the one working) while the other one is running in production. You should first try to remove this difference, see if it fixes the issue. I use a MYEXE_DEV.bat file to do that:
setlocal
set ASPNETCORE_ENVIRONMENT=development
yourbinary.exe
endlocal
Give it a try.
UPDATE:
Ok, let's try to move forward a bit then. When you launch you app by pressing F5 in Visual Studio, VS usually (it might depend on your template I guess) uses a launchSettings.json file with several launch profile, for instance below I have two predefines profiles IISExpress and WebApplication1, and in the .json file you might have parameters that explain why it's working under VS, but not when just double clicking on the exe.

Related

How to automatically reload .NET Core project in Visual Studio 2019

I tried to automatically reload ASP.NET Core project as I do using Angular with Node or NPM.
When I change the code of the .NET Core project and save, I want the web page to be automatically refreshed in the web browser.
run this command in project console
dotnet watch run
same works for visual studio code
From Develop ASP.NET Core apps using a file watcher (for 3.0)
dotnet watch is a tool that runs a .NET Core CLI command when source
files change. For example, a file change can trigger compilation, test
execution, or deployment.
The link above contains a tutorial with two sample projects:
WebApp (an ASP.NET Core web API) and
WebAppTests (unit tests for the web API).
Alternatively, you can also this nuget package for runtime compilation.
I think that dotnet watch should work. See the documentation from the link as there are various options.
Add Microsoft.DotNet.Watcher.Tools to the tools section of the
project.json file
Run dotnet restore
Execute with dotnet watch run
You can use dotnet watch. Viz. Docs
I have created custom lunch profile to make it easyer to run in VS.
"Watch": {
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run",
"launchBrowser": false,
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
According to this requirement, we need to run .net core application just like Angular application, loading the pages and contents automatically without built and manual refresh.
I had done some research and experienced that auto-reloading is not possible in ASP.NET core project. However, we have got the success, in our solution we are using dotnet watch which monitors source files and if a file changes, shuts down the application that it started, rebuilds and publishes the project, and then restarts the application then we just need to refresh page manually in the browser to get the changes which made in application, we don’t require to build or start the project.
Steps to follow to use asp.net watch:
1) Create.Net core application.
2) Open a command Window in your Web project's folder
3) Type dotnet watch run
4) Open your browser and navigate to an API or Page
5) Make a change to source code
6) Save the file
7) Go back to the browser and refresh manually
8) You should see the change reflected
Use dotnet watch to recompile the source code. Use Browser Link with "Browser reload on save" from Visual Studio to reload all your browsers. https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BrowserReloadonSave
One of the tasks automatically created in VS Code environment for a ASP.NET Core project (web, mvc, etc.) is called "watch". To check this, from ".vscode" folder, open the file tasks.json and you will see 3 tasks configuration: "build", "publish" and "watch". By default, "build" is used in launch.json. You can then go in the "configurations" section of launch.json and look for "preLaunchTask", and there, you can change the task to "watch". And that's it. Hot reload will be active when you run your web application.
Regards.
You should think triple before going forward to this option. (1) It is a resource-consuming. As it necessitates auto-build, as pre-operation, of the modified project and sometimes the whole solution. (Imagine a medium to a huge Asp.net solution composed from many projects, get built for each modification performed !! how much time is left for programming ???!!) (2), as you know, the page reload consumes much time for the first launch after a successful build !!... Hence, the time you want to gain from this option you will be wasted multiple, especially CLR-based programming languages (e.g. .NET Core). And finally, (3) your project is expected to be in need to develop test samples that can be injected automatically in the view for a better automation process, imagine how difficult it is!
Instead, try to unit test your solution, and then, any next modification is expected to be superficial and low occurring.
If you disagree with my proposition, I suggest developing a visual-studio extension that better reload the target web page on-build rather than an on-save-changes event. Next, Ctrl + b will do the job!
Where to start?
I have developed a VSIX that watches folders to load automatically specific generated files outside the VS UI. check the source code you will have an idea about the project's files management. it revolves in the EnvDTE API, please have a look in this piece of code.
Also, check the source project from here
Follow the procedure indicated in the Microsoft's page.
Nuget package Microsoft. VisualStudio. Web. BrowserLink
Install NuGet Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
app.UseBrowserLink(); in the startup.cs page on the configure method.
and enter image description here
now when you change something on your code Ctrl + Maj + enter and everything is saved and actualized on your browser.

Cannot rebuild ASP.NET Web Applicaiton missing solution file

I am taking over an ASP.NET Web Application using C# and all the code (including C# source) was given to me without the solution file (something.sln) so whenever opening the Web Application in Visual Studio 2017 I have to open by "Folder..." instead of by "Project/Solution...". Once open, I am able to make the necessary changes to the code behind files such as Default.aspx.cs or somethingElse.aspx.cs, but when I try to test the code changes by going to Run > Start Without Debugging, I couldn't find the Run menu option; I see the Build Solution button but it's disabled (greyed out).
Every time I try navigating directly to my site at http://dev.mydomain.com. The code changes I made did not get compiled neither.
So how do I get the Run or Build menu option enabled?
The easiest way to correct this issue is probably to create a new, empty ASP.NET WebForms project (and a new solution file as well if necessary) and copy your code files into it. You can then tell Visual Studio to "include" those files in the project.
You may (or may not) need to make the odd other minor adjustment too but those basic steps should get you started.
Not sure if this is related, but adding the sln file to the git ignore removed its visibility from VisualStudio. I had to open the project csproj file in VisualStudio.
THen on close, the prompt was asking me to save a new SLN file with the same solution name i was looking for. I was then able to go to the directory with the original solution in it, and then I was able to open it again in Visual Studio.
For all those who come to this post in the future, I would check your gitignore files and see if they ignored the sln file.

ASP.NET Core with Angular not updating changes

I have created a new project following this tutorial https://www.youtube.com/watch?v=ytDTkFJOJIE using aspnet core spa templates (angular to be specific).
So when I run "dotnet run" the first time it works fine, it runs the site as to be expected.
Now, when I commit a change, like delete the navbar and the references to it, the "main-server.js" and "main-client.js" don't update, nor does the site in the browser.
What am I doing wrong? If any more info is needed, let me know.
I was facing same issue. Below steps worked for me:
Delete all files from dist folder
run "ng build"
When the application runs, if you still don't see the changes, Empty cache and hard reload the chrome browser (hold browser refresh button for long, and select "Empty cache and hard reload")
It appears to be I had to set the environment variable. Although it might be set on launchSettings.json, you have to run this command
$Env:ASPNETCORE_ENVIRONMENT = "Development"
for it to work properly. Took me since yesterday to find this, hope it helps someone else.
For me the problem was Visual studio had checked in the .js and .js.map files for a few of my .ts components.
Visual Studio also checks in the main-client.js, vendor.js, and vendor.css files by default. Makes sure to either remove these from source control (recommended) or check them out before running.
In my case it failed to update because it was still running under IIS Express. I solved it by changing the profile from "IIS Express" to [project name] (both in the VS task bar and in the project properties under "Debug").
I too faced this problem while i executed my angular 7 with.net core app in IIS express in VS2017,
solved this by building the angular app(clientapp) in cmd by "ng build".
Then, close and reopen the application. so that VS loads the project again.
Now run the app using IIS express.
this worked for me. so give a try.
I have passed trought the same problem.
You have two options:
Delete the "dist" folder(this folder will be recreated everytime
you use 'ng-build')
Make the implementation equals the link below. This implementation
makes the application ignore the dist folder. It will only be used
at production environment.
Implementation

Visual Studio 2012 Web Publish doesn't copy files

I have a Web Application project in VS 2012 and when I use the web publishing tool it builds successfully but doesn't copy any files to the publish target (File System in this case).
If I look at the build output I can see everything gets copied over to obj\Release\Package\PackageTmp\ correctly but then all I see in the build output is this:
4>Done building project "{Project}.csproj".
4>Deleting existing files...
4>Publishing folder /...
4> ========== Build: 3 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
Even though it says the publish succeeded there are not files in the target directory for the publish.
I have seen this in multiple projects and sometimes it seems like the Solution/Platform configurations cause this problem but I haven't been able to pinpoint an exact cause for this.
Has anyone else seen this happening or have an idea on how to get this working correctly?
UPDATE:
I may have found a workaround for this. I just had this happen again and I was messing around with the publish settings. Once I changed the selected Configuration on the Settings tab away to another configuration and then back to the one I wanted to use all my files started publishing again. Hopefully this works on other projects in the future.
UPDATE 2:
I posted a bug on Microsoft Connect and heard back from a developer on the VS Web Developer team. He said they have fixed this issue in their internal builds and will releasing an update to the publish tool soon that will fix this problem.
UPDATE 3:
This has been recently fixed with Visual Studio 2012 Update 2
Same problem. The workaround was changing the publish settings from Release to Debug. Re-publish and then change back to Release...
This may be caused by solutions/projects that were created with the RC of vs2012. This happened to me months ago and fixed the problem by making sure my solution build configurations matched my project configurations...
I just recently experienced the same problem when opening the same solution originally created in vs2012RC with VS2012 Express for Web. I did exactly what the original poster suggested and it fixed my problem.
Here is the thread that lead me to the answer:
connect.microsoft.com/VisualStudio/feedback/details/746321/publish-web-application-fails
The pertinent response from the conversation above that helped me was:
Posted by Microsoft on 6/13/2012 at 12:00 PM Hi Andrew,
This was a bug in how we handle the solution configuration vs. the
project configuration. We incorrectly assumed that they would be the
same (e.g. Solution's Release|x86 would have each project set to
Release|x86 as well), which caused us to use the wrong build
properties for publishing files.
The workaround is to make the solution configuration and build
configuration match. This issue will be fixed in the next release of
Visual Studio 2012.
Thanks,
- Jimmy Lewis SDET, Visual Web Developer team
To take this a bit further. You have two files that are created when you create a publish profile.
NewProfile.pubxml
NewProfile.pubxml.user
When you open a project that has these files in the PublishProfile folder from a source control it only has the .pubxml file and not the .publxml.user file, so it creates the .publxml.user file on the fly when you open the project.
When it creates the new .publxml.user on the fly the xml looks like:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
When you create a new profile it creates xml that looks like:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<TimeStampOfAssociatedLegacyPublishXmlFile />
<EncryptedPassword />
</PropertyGroup>
</Project>
If you take the <PropertyGroup> node and put it in the .pubxml.user file your PublishProfiles will start working again.
An easy fix is to delete your publish profile and create a fresh one.
when you right click on your solution and select publish, you have a profile set. delete this and create a new one.
this will fix it.
I had this problem from switching from 2010 to 2012
I had same error and I change the setting from release to debug and the problem resolved..
I had this same problem however none of the answers in this thread worked for me. My issue was that there is a directory that contains dynamically generated (by my app) static HTML files. The entire directory was not being published.
The solution that worked for me was found here:
One issue I got a while back and thought I should document was that certain file types were not being uploaded when I published my project.
The file types in question were .pdf files and .rtf.
The reason this happened was because these file extensions were not recognized as requiring publishing by Visual Studio. Luckily this can be changed in Visual Studio.
Select the file(s) that aren’t being copied. In Properties ensure that Build Action is set to Content.
If this doesn’t work the following can be tried.
Under the Project menu select Package/Publish Web and notice this drop down:
Try changing this to All files in this project folder.
This is because the .pubxml.user contains required information to publish, and that file isn't (and shouldn't) be included in source control. To fix this VS bug, copy the information from the .pubxml.user file to the .pubxml file. The relevant properties are:
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
Put those in your .pubxml and you should be good to go.
I tried all of these solutions but this is the one that works every time.
We just change the "Publish method:" from "File System" to for example "Web Deploy", and immediately change it back to "File System".
I have (had) the same problem for several projects. The only ones hit seem to be web projects. Deleting and recreating the profile solves the problem only once. Additionaly, comparing the publishxml generated yields no differences, so it does not seem related to the profile at all.
The workaround mentioned by OP to change build problems back and forth seems the only reliable solution at this time.
I ran into the same problem on VS 2010, after checking publish output, event logs, turning on and checking visual studio logs etc I then decided to remove the web publish (via add/remove) which I believe had been recently updated to v1.0.30810.0. This resolved the problem.
Here we had the same problem.
We just change the "Publish method:" from "File System" to for example "Web Deploy", and immediately change it back to "File System".
The following worked for me:
Simply change from Release>Debug>Release (or vice-versa) and then publish.
No need for deleting, editing, publishing anything you don't need to.
My problem was in wrong configuration of myproject.csproj file. '_address-step1-stored.cshtml' file did not copy on publish. 'None' changed to 'Content', now it's ok.
Same problem with VS 2012 Pro with a disk publish target. Project used to publish correctly but started doing this issue where it failed to copy the files to the destination folder.
Solution was to edit the publish profile, change the mode from Release (Any CPU) to debug then back to Release (Any CPU). Doing this causes the PublishProfiles\projname.pubxml.user file to be rewritten (as described above). Looks like it added the LastUsedBuild,LastUsedPlatform and TimeStampOfAssociatedLegacyPublishXmlFile elements under the propertygroup node. After the publish is complete, it adds another ItemGroup with individual files and publish times.
For what it's worth, I eventually gave up on fighting with Web Deploy to get it to do what I wanted (copy deployable files and nothing else), so I scripted it in PowerShell and am really happy with the result. It's much faster than anything I tried through MSBuild/Web Publish, presumably because those methods were still doing things I didn't need.
Here's the gist (literally):
function copy-deployable-web-files($proj_path, $deploy_dir) {
# copy files where Build Action = "Content"
$proj_dir = split-path -parent $proj_path
[xml]$xml = get-content $proj_path
$xml.Project.ItemGroup | % { $_.Content } | % { $_.Include } | ? { $_ } | % {
$from = "$proj_dir\$_"
$to = split-path -parent "$deploy_dir\$_"
if (!(test-path $to)) { md $to }
cp $from $to
}
# copy everything in bin
cp "$proj_dir\bin" $deploy_dir -recurse
}
In my case I'm calling this in a CI environment (TeamCity), but it could easily be hooked into a post-build event as well.
This action was successful for me:
Kill Publish Profiles in "Properties>PublishProfiles>xxxx.pubxml" and re-setting again.
I found the I could get around this problem by changing the target location from obj/[release|stage|..] to a new path outside of the solution folders completely eg c:\deployment. It seems like VS 2012 was getting confused and maybe giving up somewhere during the publish process.
Matt
Had the same problem recently in VS 2013 for a MVC project in which I imported Umbraco CMS. I couldn't publish. The answer above helped, though I needed a while to figure out what I actually should do in VS. It needed some research e.g. on MS blogs to find out. I try to say it simple:
Choose in the VS toolbar a certain configuration e.g. Release and Any CPU. Run the project.
Afterwards right-click in the Solution Explorer on the solution in question, choose Publish. Create a new publishing profile or use a given one, but always make sure that in the settings the same configuration (e.g. Release and Any CPU) is chosen, as before you run the project the last time.
Additionally in my case it was necessary to delete the OBJ folder because here the settings from my last unsuccessful tries to publish got stuck, though I restarted VS and deleting all publishing profiles.
I have a Web Application with several other referenced Projects in the Solution. I've deployed successfully with a single Publish configuration many times in the past. I changed the Project Configuration from Debug to Release for a Project that had been missed in the past. The next time I attempted to deploy I got these symptoms, where the Publish just quietly fails - it does nothing and says it succeeded:
1>------ Build started: Project: Project, Configuration: DeployProduction Any CPU ------
1>
2>Publishing folder /...
========== Build: 1 succeeded, 0 failed, 9 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
The only way to recover it was to wipe out the Publish profile, close Visual Studio to force it to save the deletion, reopen it, and recreate the Publish profile from scratch. Once I did that I could Publish fine again.
Win8 VS2012, crappy laptop.
In Visual Studio 2012, switching between releases still causes problems.
We added a pre-build event to delete the obj folder: del /s /f /q $(ProjectDir)\obj and it fixed the issue of publishing. Cleaning works sometimes, but not always.
I finally found the answer by myself. All of the above solutions doesnt work for me.
What i had done is that i move the project to drive c change the project folder to something shorter and boom it publish..
the reason that it failed on my side is that i had very long project name/heirarchy.
C:\Users\user\Desktop\Compliance Management System\ComplianceIssueManagementSystem\ComplianceIssueManagementSystem
I had thought of this because sometimes when i extracted rar file it says that the name/path is too long. I thought it will be the same as visual studio 2012 publish. and it does!
hope it will help you guys.
Check your current project that whether you have made back copy with same class name and different page name (Class name will inherit copied file). Ultimately that will confuse the compiler!!!
CodeFile="Consolidated.aspx.vb" Inherits="Consolidated
None of the above solutions worked for me.
But I noticed that of our five ASP.NET MVC projects in our main solution, four of them put the deployment package in the right place, while one left it under obj\Debug.
I compared the projects and found a discrepancy. The solution was to change this:
<Import
Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
to this:
<Import
Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets"
Condition="'$(VSToolsPath)' != ''" />
<Import
Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"
Condition="false" />
After I made this change, all five projects put their deployment packages in the right spot.
(Sorry about the long lines, but I couldn't find a better way to condense them.)
I encountered this with Visual Studio generated Service Reference files becoming too long in terms of the overall path length.
Shortened them by re-generating the Service Reference using svcutil.exe, deleting all the original Service Reference files.
svcutil can be called like this:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe" /language:CS http://myservice /namespace:*,My.Namespace
My.Namespace should be replaced with the existing namespace in the generated service proxy (typically found in the Reference.cs file) to avoid compilation errors.
http://myservice should be replaced with the service endpoint url.
I've got into same problem. None of the above solutions worked for me.
So, I've excluded the files which failed to copy while publishing.
I had published the website several times. But one day when I modified some aspx file and then tried to publish the website, it resulted in an empty published folder.
On my workaround, I found a solution.
The publishing wizard will reflect any error while publishing but will not copy any file to the destination folder.
To find out the file that generates the error just copy the website folder contents to a new folder and start the visual studio with that website.
Now when you try to publish it will give you the file name that contains errors.
Just rectify the error in the original website folder and try to publish, it will work as it was earlier.
Follow these steps to resolve:
Build > Publish > Profile > New
Create a new profile and configure it with the same settings as your existing profile.
The project will now publish correctly. This often occurs as a result of a source-controlled publish profile from another machine that was created in a newer version of Visual Studio.
FIXED - various solutions offered didn't work for me. What did work for me with VS Community 2017, Windows Server 2012 R2 was to change the TEMP and TMP environmental variables for the user and then restart the system and deploy again (restarting VS was not enough). These temp variables are where VS does the temp publish.
Restarting visual studio after changing temp variables didn't do the trick, had to reboot system.
Try quitting Visual Studio, delete the relevant pubxml.user file in your PublishProfiles directory, restart VS and publish. Worked on VS 2019.
First:
Build in release Configuration.
In Project Properties-> page select All files and folders under
Package/Publish Web.
Rebuild solution (after Clean solution).
now publish.
While publishing recheck what u have opted.
this should do it. It did for me!:)

No dll compiled in visual studio 2008 express when built

I'm a .NET newb, so forgive me if this is a stupid question. I've inherited a website which I've amended and now need to rebuild. I've opened the .sln file in VS2008, made my changes to the files and clicked 'build > rebuild website'. This seems to run okay - it outputs a load of comments in a panel at the bottom as it's building, and then finally stops, saying: "Validation complete. Rebuild All: 1 succeeded, 0 failed, 0 skipped".
But when I check the bin folder, there are no dlls in there.
Does anyone know what's going wrong here? I just need to build this thing and upload the aspx and dll files and it should be sorted, but just can't seem to get it to build properly at all.
Thanks for any pointers...
If its a web project and not a web application then Visual Studio does not actually build and compile it. It just checks through for errors and let's the runtime itself compile the web pages and code behind. So you won't get a dll in the bin folder.
You can try pre-compiling your site and copying the output up to your web server.
Cheers Tigger.
Make sure you're looking in the right bin folder. It's not the one in solution explorer, and you need to make sure you're checking using the "Release" configuration bin folder and not "Debug".
It's entirely possible they are redirecting the build output to somewhere else.
Check the project properties (right click on the project name and select Properties).
On the "Compile" tab look to see what the Build Output Path is. That is where the assemblies (dll's) are going to be pushed to.
Try Click on Solution right mouse ant choose Build solution. It rebuild all your solution files not only the web page.
Go to the 'Build' menu at the top of Visual Studio and select 'Build Solution'.

Resources