I have a very strange issue with Visual Studio, whereby if I Build
my project it works successfully, however if I Rebuild
I get the following compile error
The application is a very simple, but does target multiple frameworks. (.NET 8 and .NET Framework 4.8)
CS0103 The name ‘MimeTypes’ does not exist in the current
context MimeTypesRebuild (net48), MimeTypesRebuild (net8.0)
I have been able to replicate this issue in a clean console application, is this a bug with VS? Has anyone come across this before?
Project File:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MimeTypes" Version="2.5.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Program.cs:
using MimeTypesRebuild;
var fileName = "sample.png";
var mimeType = MimeTypes.GetMimeType(fileName);
Console.WriteLine($"{fileName} has a MIME type of: {mimeType}");
Console.Read();