images folder is not included in the release build - .net-6.0

This may be another simple question. I did my research and I couldn't find a way to resolve the issue. I have .net 6 web api project. the project folder does not have a wwwroot folder. I placed images folder within the project root. i.e. src\WebUI\images\ where src\WebUI\WebUI.csproj exists. these images are being used only for email templates.
I had no issues with the development environment. but when I try to deploy files to the server, I noticed that the image folder was not included in the release build.
I have following middleware in program.cs
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "images")),
RequestPath = "/images"
});
Could someone please tell me what am I missing here?

I've just realized after posting the question that I need to add following to my src\WebUI\WebUI.csproj
<ItemGroup>
<Content Include="images\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

Related

Include a file in a Xamarin project

Here I decided to train on Xamarin. I am currently a tutorial. My problem is that when I try to add a ContentPage I only have the class file that is included in the project. If I display all the files of the project I see my view but can not include it in the project. I put you a screenshot below.
So if anyone has an idea of ​​where the problem may come from or a method to import my file I am a taker.
Thank you in advance.
Stop your project before trying to include something on it with the Visual Studio interface.
Otherwise edit the .csproj manually, which is located on the root folder of your project and put the path to your new file manually like it's made on the others. You won't see the .csproj file with Visual Studio so use another editor instead.
See this link for more details about importing it manually
Don't include .xaml and .xaml.cs files manually/separately, use the Add new class context menu instead (right click on Views folder) and select the kind of class you're interested in. The .csproj will automatically link the 2 created files like this :
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
Your .csproj seems to be confused now, I suggest you don't try to edit it manually (for now), delete all CounterPage.* and start over.

aspnetboilerplate core (the angular project)

why the "angular part" of abp .netcore template is distributed in a visual studio solution (AbpCore.AngularUI.sln)?
Is there any .netcore code inside it or some serverside functionality?
is the whole serverside code in the other solution (AbpCore.sln), or there is more?
In enterprise companies front-end and back-end developer teams are separated. So client-side and server-side code structure is seperated. But if you want you can merge the solutions following the steps below.
Merging Solutions
Step 1: Copy files from client project to server project
Copy files in below screenshot from your client solution to root folder of *Web.Host project in server solution.
Step 2: Modify tsconfig.json
If the tsconfig.json file under src folder does not contain skipLibCheck configuration, you need to add it, because current version of lodash typings has an error.
"target": "es5",
"skipLibCheck": true,
"typeRoots": [
"../node_modules/#types"
]
If the tsconfig.json file under e2e folder contains below configuration
"extends": "../tsconfig.json"
You need to change it like this, becasue above configuration is wrong.
"extends": "../src/tsconfig.json"
Step 3: Modify .gitignore file
Since we copied .gitignore file from another project, we need to remove lines under "# VS files" which contains "PhoneBook.AngularUI" keyword.
Step 4: Modify *.Web.Host.csproj
We need to exclude "node_modules", "dist" and "external_libs" folders from compiled folders. In order to do that, add below content to your csproj file's content:
<ItemGroup>
<None Include="App.config" />
<None Update="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="wwwroot\**\*">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<Compile Remove="dist\**" />
<Compile Remove="external_libs\**" />
<Compile Remove="node_modules\**" />
<EmbeddedResource Remove="dist\**" />
<EmbeddedResource Remove="external_libs\**" />
<EmbeddedResource Remove="node_modules\**" />
<None Remove="dist\**" />
<None Remove="external_libs\**" />
<None Remove="node_modules\**" />
</ItemGroup>
After doing this, your project must be build successfully.
Step 5: Running the host project
Now, we can run our host project by pressing the F5 button. We assume that, you have already applied migrations to your database and runned host project before starting this document according to ASP.NET Core & Angular 2+ document.
Step 6: Running the client (Angular 2.x) project
We need to open a command prompt and navigate to "..\src\Acme.PhoneBook.Web.Host" folder. Then we need to run "npm install" command in order to install our project's dependencies. Then we can run "npm start" command to start our project.
After this point, we can work on a single Visual Studio 2017+ solution with our client and server projects. Since we use angular-cli for serving our client application, we cannot use same port both for our client and server apps during development.
But, we can do it when publishing our application. Let's see how.
Publish Configuration
Step 1: Configure .angular-cli.json
Our client project is published by angular-cli. In order to publish a single website using Visual Studio, first we need to modify publish directory for angular-cli. In order to do that, open .angular-cli.json in your project and change value of "outDir" to "wwwroot/dist". We could use "wwwroot" as outDir but, angular-cli deletes entire folder before it builds the application. So, In order not to loose other files under wwwroot folder, we used wwwroot/dist.
Step 2: Build client app before publish
Before publishing our application using Visual Studio's publish, we need to build our angular application using angular-cli. Your *.Web.Host.csproj will be like this:
<Target Name="PrepublishScript" BeforeTargets="ComputeFilesToPublish">
<Exec Command="ng build --prod" />
</Target>
In this way, angular-cli is going to build your client application before every publish you make.
Step 3: Move client app files to wwwroot
We need to move files and folders under "wwwroot/dist" to "wwwroot". In order to do that, change your *.Web.Host.csproj like this:
<Target Name="PrepublishScript" BeforeTargets="ComputeFilesToPublish">
<Exec Command="ng build --prod"></Exec>
<Exec Command="robocopy $(MSBuildProjectDirectory)\wwwroot\dist\ $(MSBuildProjectDirectory)\wwwroot\ /S /E /MOVE" IgnoreExitCode="True" />
<ItemGroup>
<DistFiles Include="wwwroot\**\*" />
<ResolvedFileToPublish Include="#(DistFiles->'%(FullPath)')" Exclude="#(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
This command copies entire content of wwwroot\dist folder to wwwroot and deletes dist folder before publish. In this way, will have a clean wwwroot folder.
Step 4: Add middleware for angular 2.x rotues
We need to do one more thing before publising our application. Since we host our Angular 2.x application in a ASP.NET Core website, we will have a routing problem. After publishing our application, if we refresh page when we navigate to a page in our application (for example: /admin/users), we will have a empty page. Because when we request an url like http://yourwebsite.com/admin/users, ASP.NET Core will not be able to find a matching Controller. In order to overcome this problem, add below code to Startup.cs file just before "app.UseStaticFiles();" line.
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404
&& !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
});
Step 5: Remove HomeContoller
We also need to remove HomeController from our project, so the app's default route will be our angular client app. We can still access to swagger ui under /swagger/ui/index.html.
Now, we can publish our website using Visaul Studio's publish at once.
After Publish
Our client and server applications are designed to work separately. Because of that, they have different configurations. In order to make them work together, we need to make some configurations after publish as well. We need to use same address configured for our host application in appsettings.json for our angular2 application. First configure your appsettings.json file for values "ServerRootAddress", "ClientRootAddress", "CorsOrigins". ServerRootAddress and ClientRootAddress must be same since we are hosting client and server together. If you are using subdomain per tenancy, then you need to include allowed addresses into CorsOrigins, otherwise CorsOrigins will be same as ServerRootAddress and ClientRootAddress. Then, copy the value of "ServerRootAddress" in appsettings.json and use this value for "remoteServiceBaseUrl" and "appBaseUrl" in "appconfig.json" under "wwwroot\assets\" folder.
Now you can view your website under "http://yourwebsite.com/". If you want to view swagger ui, then you can use http://yourwebsite.com/swagger/ui/index.html.
Notice that, appsettings.json and appconfig.json are two different files.
Originally, you can check out asp.net zero merging angular client codes documentation
There is a checkbox to select if you want to download only one solution (AngularUI and Host project).
Please refer the image.

Why is separate resource file generated after saving?

Before modifying a resource file, it looks like this in VS.NET (2013):
Strings.resx
Strings.Designer.cs
After saving, it looks like this:
Strings.resx
Strings.Designer.cs
Strings1.Designer.cs
If I try to run the project, I get an error that Strings already exist. I have to then delete Strings.Designer.cs and rename Strings1.Designer.cs to Strings.Designer.cs.
Then I have to unload the project and modify those references in the project file XML. Then reload and all is well until I modify again.
Any idea how to fix this?
I faced the same issue. I deleted my old resource file and created a new resource file with same name and content. Now it is working fine.
So, delete the Strings.resx file and create a new file with the same name that is Strings.resx
I found the answer from this link Generating *.Designer.cs from .resx.
Basically, you need to:
Right-click on your project and click Unload.
Then right-click again and click on Edit on your project.
Find the string <LastGenOutput> and change the entry to whatever you want.
For example, I need to generate Strings.Designer.cs:
<ItemGroup>
<Compile Update="App_GlobalResources\Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="App_GlobalResources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
I hope this post can help someone in the future.
Cheers

Resources files issues in ASP.NET MVC 3

I´m having a strange problem with resources files. Strange because it was working great.
Well, I have some resources files. I created a Resources folder on my asp.net mvc 3 project structure and I am mirroring the views's folder structure. For now I have:
Views
Shared
_Layout.cshtml
Resources
Shared
Layout.pt-BR.resx
Layout.en-US.resx
Layout.ko-KR.resx
All resources files are configured as Embedded Resource, PublicResXFileCodeGenerator and with Custom Tool Namespace "ViewRes". All ".Designer.cs" files are empty. I remember to see some code in them when it was working.
On my .csproj file I have these data:
<ItemGroup>
<EmbeddedResource Include="Resources\Shared\Layout.en-US.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Layout.en-US.Designer.cs</LastGenOutput>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Shared\Layout.ko-KR.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
<LastGenOutput>Layout.ko-KR.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Shared\Layout.pt-BR.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Layout.pt-BR.Designer.cs</LastGenOutput>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
The problem is: When I try to access the #ViewRes on my views, It is not recognized. I tried already to remove the custom tool namespace but the #Resource is not recognized too. In both situations I got this compilation error:
Compiler Error Message: CS0103: The name 'ViewRes' does not exist in the current context
Does anybody have any idea?
Thanks,
Paulo
EDIT: NEW INFORMATIONS
I created a global Resources.resx file by project's properties menu in VS2010 and it's working with the custom tool namespaces I have entered. "Resources" namespace still not working. I think the problem is with the local resources files. Unfortunatly I need them because I can't rename the global resources.resx file including the culture code.
EDIT 2
I created new .resx file on Resource folder and what I can see is that the filename can not have 2 ".". Is the name is Resources.resx, it works. If the name is Resource-en-US.resx, it works but, If the name is Resources.en-US.resx it fails!
I think you can also write a custom helper, that will return by reflection the string.

Is it possible to filter on files in sub folders in ContentFiles for a web setup project?

I have a web setup project and a web site included in the same sollution.
In the setup project, I have added Content files pointing to the web site content.
In this web site there are some folders that contains dynamically generated files (i.e .log files, some image files etc.) I do not want these files to be included in the setup. I have tried to add a filter Symbols\*.png but this does not work. I have also tried a filter called *.png, and this excludes the .png files within that folder, but the problem is it also excludes all static .png files in the web site that must be there.
How can I add a filter that excludes only the files under the directory I want?
Is it possible to call something in the PreBuildEvent after the files are deleted that will tell VS to refresh the web site content?
Are there any other approaches that can solve this?
Have you tried to edit your .csproj file with notepad and add something like:
<ItemGroup>
<!-- This will exclude the .png files from the Symbols folder -->
<ExcludeFromPackageFiles Include="$(ProjectDir)..\..\MyWebSite\Symbols\*.png" />
</ItemGroup>
where ItemGroup is after the following line:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
More info you can find in the following article: http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx
As a workaround, I have created a PreBuildEvent that deletes all the files that should not be included in the setup:
del /Q $(ProjectDir)..\..\MyWebSite\Symbols\*.png
This actually deletes the files when I start the build, but it causes an error later in the build, because some content files does not exist that the setup content thinks should be there. The files that are deleted, are still referenced in VS as content in the web site. If I browse the folders in the web site, I see that the deleted files are there in the VS GUI (although the files are actually deleted). I have to do a refresh on the web site project to tell VS that the content has changed, and then do the build again. Then it works, and my setup contains what I want.

Resources