Visual Studio suggests C# 8.0 features, but compiler yields error - visual-studio-2019

In my projects Visual Studio gives me recommendations to use C# 8.0 features for Framework 4.6 projects, even though the default is specified on the Microsoft documentations to be 7.3. An example of one of the suggestions:
var i1 = "";
var i2 = "";
i1 = i1 ?? i2; //suggests i1 ??= i2;
If I let VS correct the suggestions the IDE shows me no errors or warnings, but the moment I build I get a compiler error.
I know I can change the langversion in the .csproj file to get it to work, but that's not the point.
Why do I get suggestions and then proceed to get no errors until compilation?
In my memory I used to get suggestions to automatically upgrade the project to the langversion for 7.X features in the past, if I wanted to use features from that version.
Example of one of the .csproj files:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{00000000-0000-0000-0000-000000000000}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
//... References & compilation files
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Updating the Microsoft.Net.Compilers NuGet package worked for me.
I updated from 2.10.0 to 3.11.0.

Related

OutputPath when using multiple TargetFrameworks

How to specify output path only for single target framework in new SDK csproj project style.
My project file has this PropertyGroup:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
</PropertyGroup>
I tried to add something like this above this group but didn't worked:
<Choose>
<When Condition=" '$(MyMsbuildParam)' == 'False' ">
<PropertyGroup>
<TargetFrameworks>net5.0-windows10.0.18362.0;net472</TargetFrameworks>
</PropertyGroup>
</When>
<When Condition=" '$(MyMsbuildParam)' == 'True' ">
<PropertyGroup>
<TargetFrameworks>net472</TargetFrameworks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath >..\bin64\$(Configuration)\</OutputPath>
</PropertyGroup>
</When>
</Choose>
This is the error I'm getting:
Error MSB4044 The "ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework".
C:\Program Files\dotnet\sdk\5.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 241

Publish Website Does not Use Transformed web.config

I created a solution containing a website (not WebApp) with VS Express 2013. I use a web.Release.config file for the publish process. That worked well with VS 2013.
Now that I changed to VS 2019 Community, web.Debug.config was used for the web.config transformation though the publish was done for "Release". I suppose that is because in the configuration manager only "Debug" is possible for any configuration.
In another thread I found that I had to change website.publishproj from Debug to Release:
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
Now, web.Release.config is used for the transformation:
"web.config" wurde mithilfe von "C:\Users\<project path>\Web.Release.config" in "C:\Users\<some temporary path>\obj\Release\TransformWebConfig\transformed\web.config" transformiert.
This file actually has the changes applied that are needed for Release.
However, in the destination directory web.config does not contain these changes. It seems to be the original web.config without transformation.
What must I do to make Publish copy the transformed web.config?
This is my .pubxml file:
<?xml version="1.0" encoding="utf-8"?>
<!--
Auto generated comment...
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Inetpub\vhosts\<website name>.com\httpdocs</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
and here is website.publishproj:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.30319</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{45ff7195-6038-4b17-91ce-611a467ac837}</ProjectGuid>
<SourceWebPhysicalPath>$(MSBuildThisFileDirectory)</SourceWebPhysicalPath>
<SourceWebVirtualPath>/(Source Path Name)</SourceWebVirtualPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SourceWebProject>http://localhost:56406</SourceWebProject>
<SourceWebMetabasePath>/IISExpress/7.5/LM/W3SVC/2/ROOT</SourceWebMetabasePath>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<!-- for VS2010 we need to use 10.5 but for VS2012+ we should use VisualStudioVersion -->
<WebPublishTargetsVersion Condition=" '$(WebPublishTargetsVersion)' =='' and '$(VisualStudioVersion)' == 10.0 ">10.5</WebPublishTargetsVersion>
<WebPublishTargetsVersion Condition=" '$(WebPublishTargetsVersion)'=='' ">$(VisualStudioVersion)</WebPublishTargetsVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(WebPublishTargetsVersion)</VSToolsPath>
<_WebPublishTargetsPath Condition=" '$(_WebPublishTargetsPath)'=='' ">$(VSToolsPath)</_WebPublishTargetsPath>
<AssemblyFileVersion Condition="'$(AssemblyFileVersion)' == ''">1.0.0.0</AssemblyFileVersion>
<AssemblyVersion Condition="'$(AssemblyVersion)' == ''">1.0.0.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<AssemblyAttributes Include="AssemblyFileVersion">
<Value>$(AssemblyFileVersion)</Value>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyVersion">
<Value>$(AssemblyVersion)</Value>
</AssemblyAttributes>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Accessories\Lib\Runtime\BaseLib\BaseLib.csproj">
<Project>{8A827F3E-CA83-4765-988D-937B0B608201}</Project>
<Name>BaseLib</Name>
</ProjectReference>
<ProjectReference Include="..\Accessories\Lib\Runtime\Config\Config.csproj">
<Project>{1B78D777-B4F8-4CEA-9A4F-554807D1E5BF}</Project>
<Name>Config</Name>
</ProjectReference>
<ProjectReference Include="..\Accessories\Lib\Runtime\GardenLib\GardenLib.csproj">
<Project>{30B09928-B911-4803-982F-519C4CDB8860}</Project>
<Name>GardenLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(_WebPublishTargetsPath)\Web\Microsoft.WebSite.Publishing.targets" />
</Project>
After I got some more problems publishing my website, I switched back to VS2013 Express where my publish process works well as it did before.
Maybe it's a bug in Visual Studio?

error MT1108: Could not find developer tools for this device

I have an Xamarin iOS application that can run fine on my device when I start the application on "Debug" configuration. Now I created a new configuration called "Staging" and duplicated the info.plist and entitlements.plist as info-Staging.plist and entitlements-Staging.plist and want to use those while debugging in the "Staging" configuration. The only difference between them is a different identifier (com.blah.blah). I edited the .csproj as so:
<ItemGroup>
<None Include="packages.config" />
<None Include="Entitlements.plist" Condition="'$(Configuration)' != 'Staging'" />
<None Include="Info.plist" Condition="'$(Configuration)' != 'Staging'" />
<None Include="Info-Staging.plist" Condition="'$(Configuration)' == 'Staging'">
<LogicalName>Info.plist</LogicalName>
</None>
<None Include="Entitlements-Staging.plist" Condition="'$(Configuration)' == 'Staging'">
<LogicalName>Entitlements.plist</LogicalName>
</None>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Staging|AnyCPU' ">
<Optimize>false</Optimize>
<OutputPath>bin\Staging</OutputPath>
<DefineConstants></DefineConstants>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<CodesignEntitlements>Entitlements-Staging.plist</CodesignEntitlements>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
<AssemblyName>MyApp.iOS</AssemblyName>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<ConsolePause>false</ConsolePause>
<DeviceSpecificBuild>true</DeviceSpecificBuild>
<MtouchDebug>true</MtouchDebug>
<MtouchFastDev>true</MtouchFastDev>
<MtouchFloat32>true</MtouchFloat32>
<MtouchArch>ARMv7, ARM64</MtouchArch>
<MtouchTlsProvider>Default</MtouchTlsProvider>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
But when I try to build the app on my device, I get this message:
error MT1108: Could not find developer tools for this 10.2.1 (14D27) device. Please ensure you are using a compatible Xcode version and then connect this device to Xcode to install the development support files.
This Problem is very simple Actually Just check if the Installed Xcode version in your MAC machine and the Xamarin version that you have right now in your System match. For that you need to check in Visual studio as Tools/Options/Xamarin

Replace values in xml using ANT

I want to replace the ProductVersion value at <DefineConstants> node of the following xml. Remaining part of the line has to be preserved.
Example:
<DefineConstants>XXXXX;ProductVersion=20.323.23;YYYYY</DefineConstants>
to
<DefineConstants>XXXXX;ProductVersion=21.58.44;YYYYY</DefineConstants>
I tried the replaceregexp but it changes the remaining contents.
<replaceregexp file="${basedir}\Installer.wixproj"
match="ProductVersion=([0-9].*);(.*)"
replace="ProductVersion=${SpaceVersion};\1"
byline="true"
/>
Could you guide me what i am doing wrong in this.
XML:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.5</ProductVersion>
<ProjectGuid>{6bc0a85b-9c15-41e6-874b-5fe07e5338e6}</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>Installer</OutputName>
<OutputType>Package</OutputType>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;</DefineConstants>
<WixVariables>
</WixVariables>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>SourceDir=$(SolutionDir)XSSE\;ProductVersion=3.3.1.75;ProductName=XSSE;ToolchinShortcut=XSSEToolchinShortcut;ExtensionDir=XSSE;ManifestFileName=extension.vsixmanifest;PkageDefFileName=XSSE.ToolchainProvider.pkgdef;REGKEY=Software\Microsoft\XSSE;</DefineConstants>
<WixVariables>XYZ=123;</WixVariables>
</PropertyGroup>
<ItemGroup>
<Compile Include="filefragment.wxs" />
<Compile Include="Product.wxs" />
</ItemGroup>
<ItemGroup>
<WixExtension Include="WixUIExtension">
<HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
</ItemGroup>
<Import Project="$(WixTargetsPath)" />
I think trying to capture the remainder of the line after the product version is unnecessary.
You don't need to worry about that. If your regex leaves the rest of the text alone, you can just replace the ProductVersion only.
I had success with this:
<replaceregexp file="${basedir}\Installer.wixproj"
match="ProductVersion=[0-9]+\.?[0-9]+\.?[0-9]+\.?[0-9]+\.?;"
replace="ProductVersion=${SpaceVersion};"
byline="true"
/>
You need to use \2 instead of \1.
<replaceregexp file="${basedir}\Installer.wixproj"
match="ProductVersion=([0-9].*);(.*)"
replace="ProductVersion=${SpaceVersion};\2"
byline="true"
/>
Standalone test:
<project default="test">
<property name="SpaceVersion" value="a.b.c"/>
<target name="test">
<replaceregexp file="test.xml"
match="ProductVersion=([0-9].*);(.*)"
replace="ProductVersion=${SpaceVersion};\2"
byline="true"
/>
</target>
</project>
Comparison of changed file with original:
$diff test.xml test.xml.0
2c2
< <DefineConstants>XXXXX;ProductVersion=a.b.c;YYYYY</DefineConstants>
---
> <DefineConstants>XXXXX;ProductVersion=20.323.23;YYYYY</DefineConstants>

Delphi 2009 MS Build headaches

does anyone know of any good description of delphi's build system? (i know it's using MS Build.) i'm using delphi 2009.
i wanted to set up a variation of the Debug build configuration that (often) has different defines (d2009 seems to call them "preprocessor symbols").
the problem i'm having is that--even though i turned off "inherit" for "Base" and "Debug"--have only very limited control. for example, i can't get rid of FastMM_.
<PropertyGroup>
<ProjectGuid>{D7FE7347-8E2C-438C-A275-38B8DA9244B0}</ProjectGuid>
<ProjectVersion>12.0</ProjectVersion>
<MainSource>oca.dpr</MainSource>
<Config Condition="'$(Config)'==''">Debug</Config>
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_StringChecks>off</DCC_StringChecks>
<DCC_MinimumEnumSize>4</DCC_MinimumEnumSize>
<DCC_RangeChecking>true</DCC_RangeChecking>
<DCC_IntegerOverflowCheck>true</DCC_IntegerOverflowCheck>
<DCC_UNIT_PLATFORM>false</DCC_UNIT_PLATFORM>
<DCC_SYMBOL_PLATFORM>false</DCC_SYMBOL_PLATFORM>
<DCC_DcuOutput>.\dcu</DCC_DcuOutput>
<DCC_UnitSearchPath>C:\Prj\Lib\AutoQADocking\Delphi2009.Win32\Lib;$(BDS)\Source\DUnit\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Optimize>false</DCC_Optimize>
<DCC_DependencyCheckOutputName>oca.exe</DCC_DependencyCheckOutputName>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias>
<DCC_Platform>x86</DCC_Platform>
<DCC_E>false</DCC_E>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
<DCC_F>false</DCC_F>
<DCC_K>false</DCC_K>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_PentiumSafeDivide>true</DCC_PentiumSafeDivide>
<DCC_Optimize>true</DCC_Optimize>
<DCC_IntegerOverflowCheck>false</DCC_IntegerOverflowCheck>
<BRCC_Defines>MadExcept;FastMM;$(BRCC_Defines)</BRCC_Defines>
<DCC_AssertionsAtRuntime>false</DCC_AssertionsAtRuntime>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
<DCC_DebugInformation>false</DCC_DebugInformation>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
<BRCC_Defines>FastMM</BRCC_Defines>
<DCC_DebugDCUs>true</DCC_DebugDCUs>
<DCC_MapFile>3</DCC_MapFile>
<DCC_Define>DEBUG;FastMM_;madExcept;$(DCC_Define)</DCC_Define>
</PropertyGroup>
i even had to edit it today with notepad to get rid of a DCC define that the delphi UI doesn't seem to give access to. (it said "From Delphi Compiler" for the item i couldn't remove.)
does anyone know a good primer on the use of this feature in delphi?
thank you!

Resources