.net core wwwroot data folder - Do Not Copy being ignored - visual-studio

So I have a simple .net core application that I am deploying to Azure from VS2019. I have some json files in the wwwroot\data folder and I have set them to content=none and copy="Do Not Copy".
However when I publish the still publish every time.
I have also edited the .csproj file and ensure this is there
<ItemGroup>
<None Include="wwwroot\data\file.json" CopyToPublishDirectory="Never"/>
</ItemGroup>
and yet it still publishes.
Any ideas

You can try following code:
<ItemGroup>
<Content Update="wwwroot\data\file.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>

Related

Change LibSassBuilder output directory

I'm using LibSassBuilder in a Blazor project. I have read the docs and it's unclear to me if the package's config allows you to specify an output directory. I'd prefer to keep my .scss files outside of wwwroot and just place the compiled .css files there-- but I don't see if there's a way to do this. If not, is there a way to specify a file move to wwwroot in the Visual Studio build pipeline?
I'm also developing a Blazor project using LibSassBuilder. This is how I got it to work in my .csproj file:
<PropertyGroup>
<LibSassOutputStyle>compressed</LibSassOutputStyle>
<LibSassOutputStyle Condition="'$(Configuration)' == 'Debug'">expanded</LibSassOutputStyle>
</PropertyGroup>
<ItemGroup>
<CSSFiles Include="**/*.css" />
</ItemGroup>
<Target Name="MoveCSS" AfterTargets="Build">
<Move SourceFiles="#(CSSFiles)" DestinationFolder="wwwroot/css" />
</Target>

build project without runtimes folder but included nuget packages in nopcommerce 4.40(.net 5 and VS 2019)

I'm developing plugin for nopcommerce,
I'm using VS 2019 and nopcommerce 4.40.4(.net 5)
I should use a nuget package in my plugin,
If I set CopyLocalLockFileAssemblies to true, when I build my project, it created runtimes folder, which is about 65 MB,
If I set CopyLocalLockFileAssemblies to false, it does not create runtimes folder, but, the dll of nuget package which I should use, not included in the build folder,
would you please help me about this?
Note: set copy local to no, make no difference when I change for Nop.Services which I use in the project
this is my csproj and my the package is > SmsIrRestful.NetCore :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputPath>..\..\Presentation\Nop.Web\Plugins\AttributeStockSMS</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<!--Set this parameter to true to get the dlls copied from the NuGet cache to the output of your project.
You need to set this parameter to true if your plugin has a nuget package
to ensure that the dlls copied from the NuGet cache to the output of your project-->
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
</ItemGroup>
<ItemGroup>
<None Remove="plugin.json" />
</ItemGroup>
<ItemGroup>
<Content Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SmsIrRestful.NetCore" Version="1.1.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\Nop.Services\Nop.Services.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<Target Name="NopTarget" AfterTargets="Build">
<!-- Delete unnecessary libraries from plugins path -->
<MSBuild Projects="#(ClearPluginAssemblies)" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="NopClear" />
</Target>
</Project>
Instead of using NuGet reference, include the dll file of that NuGet package. For example, You are going to use TaxJar library then follow these steps.
Added NuGet reference.
Right click on NuGet package and go to properties.
Copy path value from property values as below.
Go to that path in file explorer.
Find dll file(s) from there, copy-paste into your plugin folder and add refence.
Repeat same procedures for dependent packages also (if any).
Mark as Copy Local to Yes from properties.

VS 2019 Solution Explorer references files from old Nuget packages

I'm using Visual Studio 2019 for a .NET Core 3.1 MVC application. I have installed several Nuget packages that I also created. Some of the packages contain their own settings files which need to be copied to the output directory in order for the application to work properly. These settings files are put into their own folder and everything is mostly fine. Sample .csproj file of one of these packages:
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>[redacted</Authors>
<Company>[redacted</Company>
<Description>[redacted]</Description>
<Version>1.0.2.2-alpha</Version>
</PropertyGroup>
<ItemGroup>
<None Remove="settings\mySettings.Development.json" />
<None Remove="settings\mySettings.Production.json" />
<None Remove="settings\mySettings.Staging.json" />
</ItemGroup>
<ItemGroup>
<Content Include="settings\mySettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Pack>true</Pack>
</Content>
<Content Include="settings\mySettings.Production.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Pack>true</Pack>
</Content>
<Content Include="settings\mySettings.Staging.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Pack>true</Pack>
</Content>
</ItemGroup>
What's strange is when I update one of these packages, sometimes Visual Studio doesn't link to the settings file in the updated package. So for example, this is my .csproj file for the web application.
<Content Update="..\..\..\..\..\.nuget\packages\mypackage\1.0.2.2-alpha\contentFiles\any\netstandard2.0\settings\mySettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="..\..\..\..\..\.nuget\packages\mypackage\1.0.2.2-alpha\contentFiles\any\netstandard2.0\settings\mySettings.Production.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="..\..\..\..\..\.nuget\packages\mypackage\1.0.2.2-alpha\contentFiles\any\netstandard2.0\settings\mySettings.Staging.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
This part looks fine, even if I had to manually change the paths from absolute to relative.
But in the Solution Explorer, when I view the properties for these files, it shows the build action as None and the path is to an older package version. If I then change the build action to Copy always, VS will add instructions for copying the older file to the .csproj.
This is potentially a problem in that if another developer takes over this project, they may not notice the version differences and if they change the build action, they could overwrite the correct settings file with the older one.
I don't see any reference to the older version in the .csproj file, so where is that coming from? Note that the older version of the package is not installed anywhere the solution, either. Does anyone know what the deal is?
Thanks.
You have to clean the nuget cache first or just delete all files under C:\Users\Administrator\.nuget\packages.
Not sure that if your old package version is the same as the new one. In other words, you still make a same package version and did not assign a new one for it which makes VS always install that old one from the nuget cache. So you have to clean the nuget cache folder to remove all the old packages.
So my suggestion is that when you install the new release version of the nuget package, you have to clean nuget caches first, also delete bin and obj folder.
Besides, if you want to make the conent files of the nuget package be copied into the main project's output folder. Please use
<PackageCopyToOutput>true</PackageCopyToOutput>
Check this similar issue.

msbuild task that works from publish profile to remove specific file

Have 3 json files in my project. For a specific publish profile, using a FileSystem publish and I'm trying to find a way to have a specific file NOT be published to the target folder. This is for a .net core console app.
This is my publish profile, but the file Im trying to restrict from being published is still published to the target folder.
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Debug</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PublishDir>D:\projects\test_publish</PublishDir>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeFilesFromDeployment>appsettings.Test.json</ExcludeFilesFromDeployment>
</PropertyGroup>
</Project>
Note: project file includes these files so they will be in the build output. Might this prevent the appsettings.Test.json from being deleted and hence still get copied over to the publish dir?
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.Local.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.Test.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
The work-around solution I have come up with is similar to another project I have. It involves taping into the build system and add some extra bits into the csproj file.
So the csproj file would now look like this. It eliminates the file you dont need, and you only need to add a corresponding build config entry and this uses the VS build system to determine which of these json file(s) get output.
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.Local.json" Condition=" '$(Configuration)' == 'Debug' " >
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.Test.json" Condition=" '$(Configuration)' == 'Test' " >
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
This is my publish profile, but the file Im trying to restrict from
being published is still published to the target folder.
I test it in my local machine and reproduce same issue. Also I find if I use this element in web application like asp.net, it always works. So I assume this element is not supported for publishing .net core console application.
What role does that file play in your project?
1.If your application don't need it in build output directory and publish directory, you can set the Copy to Output Directory to Do not copy.
And then clean your publish folder and publish again to check if it helps.
2.And if you have specific reason that you need the file in build, but need to exclude it from publish folder, trying adding this script into your xx.csproj(Delete Task):
<Target Name="CustomTarget" AfterTargets="_PublishNoBuildAlternative">
<Delete Files="$(PublishDir)\appsettings.Test.json"/>
<!--<Delete Files="$(PublishDir)\appsettings.xxx.json"/>-->
</Target>
You can add MSbuild Conditions like Condition="$(Configuration)=='xxx'" to the targets to make it more flexible.

Xamarin.Forms netstandard project broken with update to VS 2017.3

So today i made the mistake of updating my IDE to 2017.3.
I was then notified of incompatibilities such as
"NU1202: The package Xamarin.Forms 2.3.4.247 is not compatible with netstandard1.5. Package supports: list of targets such as monoandroid10, xamarinios10, etc"
After investigating the matter on google i found some information to try fix the project.
https://github.com/NancyFx/Nancy/issues/2647#issuecomment-265927440 suggests adding a frameworkmoniker to get it to build (At some point during fix attempts i had a platform warning too)
Another attempt i've made to fix the issue was recreating the project as a fresh template version of using a netstandard project (the project i've provided for repro was created during the time when project.json was still a thing)
You may ask why: While looking for the issue i read that some are false positive error messages, which can be disabled like this Package Reference Warning Ignore - However in this project type which is entirely based on .csproj again i was unable to add Xamarin.Forms 2.3.4.247.
So my question is:
Has anyone been able to get a similar project running on vs2017.3 yet?
REPRO project:
GitHub
After changing my project similar to a result of this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.5</TargetFramework>
<PackageTargetFallback>portable-net45+win8+wpa81+wp8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="App.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
<PackageReference Include="Xamarin.Forms" Version="2.3.4.247" />
</ItemGroup>
<ItemGroup>
<Compile Update="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Update="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
the project compiled again.
<PackageTargetFallback>portable-net45+win8+wpa81+wp8</PackageTargetFallback>
fixed the issue.

Resources