Intro
This time, I will try adding some files like .csproj, .dll, .resx, .json, and etc.
Environments
- .NET ver.5.0.103
Add references to .csproj files
Situations
- There are two projects in a solution.
- One is a xUnit project (AddFileSampleTest.csproj), another one is an ASP.NET Core project (AddFileSample.csproj).
- I want to make the xUnit project refers the ASP.NET Core project.
What I did
I executed this command.
dotnet add AddFileSampleTest reference AddFileSample
Result
AddFileSampleTest.csproj
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<ProjectReference Include="..\AddFileSample\AddFileSample.csproj" />
</ItemGroup>
</Project>
Add references to NuGet packages
Situations
- I want to make the ASP.NET Core project refers ClosedXML(ver.0.95)
What I did
I executed this command.
dotnet add AddFileSample package ClosedXML -v 0.95
Result
AddFileSample.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.95" />
</ItemGroup>
</Project>
- If I omitted "-v 0.95", the latest version package will be added.
- The case of package name is ignored. So I can write like "dotnet add AddFileSample package closedxml". But the case of the package name in the .csproj file also will be the same.
AddFileSample.csproj
...
<ItemGroup>
<PackageReference Include="closedxml" Version="0.95" />
</ItemGroup>
...
Add references to .dll files
Because I couldn't find to add references to .dll file, I edited the .csproj file directly.
AddFileSample.csproj
...
<ItemGroup>
<Reference Include="ClosedXML">
<HintPath>Resources\ClosedXML.dll</HintPath>
</Reference>
</ItemGroup>
...
For "HintPath", I can use both relative and absolute paths.
Referencing a .NET DLL directly, using the .NET Core toolchain | by Toni Solarin-Sodara | Medium
Add references to .resx files
I don't need do anything to add references to .resx files.
After I created .resx files what were named like "Controllers.HomeController.en-us.resx", CLI would output "en-us" folder into bin/Debug/net5.0 directory.
To get strings from .resx files, I can use "IStringLocalizer", designer class, and etc.
- Globalization and localization in ASP.NET Core | Microsoft Docs
- c# - How to get the .resx file strings in asp.net core - Stack Overflow
Add references to .json(or .txt etc.) files
I just add the files into the project.
But I have to update the project file to include as an output file.
AddFileSample.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<ItemGroup>
<Content Update="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Top comments (0)