Visual studio 2019 - Publish to a folder does not publish all files - visual-studio-2019

Using Visual Studio 2019 Community 16.3.6
I have a simple ASP.Net core 3.0 website project (mostly empty at this point), but I did add a web root folder (www) and a static index.html file within that folder, as shown below:
website0
> www
- index.html
> Program.cs
> Startup.cs
When I try to publish to a folder locally (as a test), for example, I specify the destination as:
D:\ws0
All of the required files are copied, EXCEPT for the "www" folder and any files within it.
Hence, when I run the project, I get 404 errors because the static files were NOT copied during the publish operation.
WHY????
Any advice would be appreciated.

Poking around in the documentation at:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.0#folder-publish-example
I found this little tidbit:
When publishing ASP.NET Core web apps, the following assets are
included:
- Build artifacts
- Folders and files matching the following globbing patterns:
**\*.config (for example, web.config)
**\*.json (for example, appsettings.json)
wwwroot\**
Since I used "www" instead of "wwwroot", I suspect the "www" folder (and anything within) will NOT be copied.
SOLUTION:
1 - In Visual Studio, right-click on the project name, then click on "Edit Project File"
2 - Include the following entry in the {project-name}.csproj file:
<ItemGroup>
<Include="www\**" CopyToPublishDirectory="Always"/>
</ItemGroup>
3 - Save the file.
When you setup a Publish profile, the "www" folder and anything beneath will be included.

Related

Unable to copy file 'source' to 'destination' while building application in visual studio 2022

I am working on Web API Project in ASP.NET Core using .NET 6.0. I have also added some features of MVC to view the data. Everything was working fine. Suddenly, while modifying the project, i have tried to build the application, i have received error
Unable to copy file
"D:\Soliton\Applications\MachineManagement\ServerAPI\MMAPIApp\MMAPIApp\obj\Debug\net6.0\apphost.exe"
to "bin\Debug\net6.0\MMAPIApp.exe". Access to the path
'bin\Debug\net6.0\MMAPIApp.exe' is denied.
I have tried to give rights to everyone to the source and destination folders.
The path 'bin\Debug\net6.0\MMAPIApp.exe' is an executable file, and not a directory. Whatever you modified, you probably inputted the incorrect path. You probably meant bin\Debug\net6.0 as this would be a valid directory path to copy a file to.

Dynamic library copied from VS to Docker not working : file too short

I created a VS server-side blazor app that I want to containerize in Docker - I use the default Dockerfile generated by VS 2022.
The project uses a dynamic library, call it libMyLib.so that depends on another lib, say libBase.so - which comes from an external source with symbolic link files, i.e. I have libBase.so, libBase.so.0 and libBase.so.0.0.0. When I check the files content it appears that both libBase.so and libBase.so.0 point to libBase.so.0.0.0 (file sizes confirm this: first two files are 1Kb and so.0.0.0 is way larger).
What I did is
Create a lib folder containing all lib files (i.e. libBase.so, libBase.so.0, libBase.so.0.0.0 and libMyLib.so)
Make sure the files are copied (Build Action: None and Copy if newer)
Make sure the docker container has valid path: ENV LD_LIBRARY_PATH="/app/lib:${LD_LIBRARY_PATH}
When I run the container and check the dependencies, I check the lib folder content - all files are there. Then I check for dependencies ldd lib/libMylib.so and I get
error while loading shared libraries: /app/lib/libBase.so.0: file too short
I am surprized it looks for libBase.so.0 and not libBase.so.0.0.0
Also puzzling me is why Visual Studio seems to consider libBase.so.0 as a "sub-file" of libBase.so - it is shows following structure:
-lib
> libBase.so
libBase.so.0
> libBase.so.0.0.0
Is this a reason that VS corrupts files when copying them the the container?
I eventually got it working deleting libBase.so.0 and libBase.so and renaming libBase.so.0.0.0 as libBase.so.0 - but why wouldn't it work out of the box with the provided symbolic link files?

ASP.NET MVC project with a section written in Angular2: a build error occurs when using MvcBuildViews

Ok it could be a singular combination...
INTRODUCTION
I have an existing ASP.NET MVC 5 project.
It contains a private "Admin" area. I'm planning to change this area migrating it to Angular2 (+ WebAPI) :)
Due to some business requirements, I can't change the architecture of the original "Main" website (separating the Admin section into another website) so I must host inside it the new "Admin" area written in Angular2.
Main website url: http://www.example.com
Admin area url: http://www.example.com/admin
This is also true for the Visual Studio Project:
I created a folder "admin" and put all Angular2 stuff in it.
All works fine...
THE ISSUE
My ASP.NET project uses the MvcBuildViews parameter to build the MVC views on Release mode.
Now when I run the build in Release mode I receive this error:
\node_modules\selenium-webdriver\lib\test\data\web.config(29): error
ASPCONFIG: It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This
error can be caused by a virtual directory not being configured as an
application in IIS.
The error doesn't have sense for me...
MSBUILD has analyzed a web.config file inside the "node_modules".
The node_modules folder has been created in the project root folder after "npm install" (necessary to prepare angular2's stuff).
These folder should be ignored by msbuild... IMHO
HEY... node_modules IT IS NOT included in the VS project. MSBUILD is scanning the folder because it is only present inside the project...
WORKAROUNDS
Give up the MvcBuildViews... but I think this setting is very useful to detect errors during development phase
Hide the node_modules folder. This is the current workaround I'm using. I've added this pre-build event attrib +h "$(ProjectDir)node_modules"
Some other solution?
I've googled with no success...
I had the same issue recently. I found the solution to this issue in the following article:
Excluding node_modules folder from ASP.NET compilation
The article suggest to replace the AspNetCompiler task in your csproj for a direct call to aspnet_compiler.exe which support excluding folders. In the article, it does so by hardcoding the path to that .exe file. Which for most of the cases is Ok.
You may also use $(FrameworkDir) and $(FrameworkVersion) to avoid hardcoding the path or if you are unsure where the aspnet_compiler.exe may be:
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<Exec Command="$(FrameworkDir)\$(FrameworkVersion)\aspnet_compiler.exe -v temp -p $(WebProjectOutputDir) -x node_modules"/>
</Target>

How do i deploy MVC3 website to server via ftp

i was able to publish the website to local machine folder, where i've the bin, content, scripts, views, web, global, and packages folder.
AFter i add these folders to the root of my web server using filezilla, the website does not work. server does support asp.net 4, ii7.
What exactly are the steps. i looked for some answers googling, but none of it helped. I'd realy appreciate if you can help me figure this out, thanks
UPDATE Issue Fixed: My project was using .net 4.5 instead of 4.0...which was causing the issue on the server where I was deploying my website
There are 2 steps in order to deploy your application:
1. If ASP.NET MVC 3.0 is not installed on the server you should deploy the following set of assemblies in the bin folder of your web
application:
Microsoft.Web.Infrastructure.dll
System.Web.Helpers.dll
System.Web.Mvc.dll
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
you can set copy local to true but this is not available for all listed dll's or you can use some interesting future: right click on the project and select Add Deployable Dependencies with ASP.NET checkbox checked.A special folder named _bin_deployableAssemblies will be created with all necessary assemblies copied into this folder. When the project will be compiled all this assemblies will be copied into bin folder.
2. Publish the application: in a local folder and copy it to your deployment server or directly via FTP.
Marking references as Copy to Bin Directory in the properties window will make sure that the DLL is copied to the /bin directory.

Teambuilding and deploying a dll (e.g. wpftoolkit.extended.dll)

The app I work on needs to use the wpftoolkit.extended.dll (i.e. no source, no msi/installer, we've only got the dll). So far we've placed the dll in a c:\libs folder on both the dev's laptop and the teambuild server and it built ok on both; now for deploying we want to add it to an installer (.vdproj) and we think we'll need it in tfs's repository somewhere. However, when tested the app now only builds on the dev's laptop and not on the teambuild server (looks like a relative path thing).
So... rather than fixing the actual problem, I'm wondering what's the best/cleanest/commonlyAccepted way to do this? where should I keep the dll in the repository and where should I place the dll on the host we're deploying to?
You should use folder structure on the source control like the following
/Main Contains the .sln file
/Source
/MyApp1 Contains MyApp1.sln file
/Source Contain folder for all
/ClassLibrary1 Contains ClassLibrary1.csproj
/MyApp1Web Contains Default.aspx
/Build Contains build output (binaries)
/Docs Contains product docs etc
/Tests
**/3rdpartyDlls** Contains all vesions of third-party dlls
For more information about the source control folders and best practices, it's recommended to read the book patterns & practices Team Development with TFS Guide (Final Release)

Resources