简体   繁体   中英

Cannot find views when running dot net core MVC website

I have developed an ASP.NET Core MVC website using Visual Studio for Mac. When I run the application through the IDE everything works as expected.

After running:

dotnet publish -c Release

and then:

dotnet my-project-name.dll

the application starts as expected, however it does not seem to be able to load any view files:

在此处输入图片说明

The 'Landing' view is stored in /Views/Shared

I've tried adding the following line to my WebHostBuilder:

.UseContentRoot(Directory.GetCurrentDirectory())

This removes the error message from the console, however the home page still does not load.

(NOTE: the 'Landing' view is used by the default endpoint)

All suggestions and questions welcome. James

Having looked at this answer , It looks like you might be missing the copy to output directory directive in the csproj file. I had what looks like the same problem and adding the following fixed it for me.

<ItemGroup> <Content Include="Views\\**\\*" CopyToOutputDirectory="PreserveNewest" /> </ItemGroup>

I added this "Content" block to an existing "ItemGroup" with other "Content" entries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM