Visual Studio 2012 Fails To Build New Project That References Other Projects - c#

I have a solution that has been working for several years. Today I went to add a new project for the first time in months of constant development. Everything was fine and coded away. Went to build and found that it cannot find any of the project references I added.
The type or namespace name 'blah' could not be found (are you missing a using direcive or an assembly reference?)
These references are to projects in the same solution and verified they are project references in the CSPROJ file. Visual Studio has no issue finding the reference because I can code against the referenced objects just fine. It's only when I build that I have issues. Currently doing Debug with AnyCPU.
Doing Google searches, I kept finding notions that the issue could be the target framework is .NET 4 Client Profile in either my new project or references. However, this is not the case. All projects are .NET 4, not Client Profile (I verified). The even weirder thing is that these references are all working fine in the existing projects.
I can get it to build if I make the new project .NET 4.5 which makes me think that something is wrong with my target framework of .NET 4. I am currently lost and not sure what to do.
Below is the project file. I had to clear the file names and project names.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{48AED04F-6928-45F4-8C1D-A5E6713B5120}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyNamespace</RootNamespace>
<AssemblyName>MyNamespace</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Build\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SomeFileThatReferences.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ref1.csproj">
<Project>{6E0EEABF-52D7-4020-9242-AFDC33B5DAA0}</Project>
<Name>Billing.Bills</Name>
</ProjectReference>
<ProjectReference Include="..\Ref2.csproj">
<Project>{6764A403-DA4C-42FF-A89F-E1EEA7FEF0A3}</Project>
<Name>Billing.Business</Name>
</ProjectReference>
<ProjectReference Include="..\Ref3.csproj">
<Project>{9D9AB79F-D52A-4EC8-B2B7-9C605EFDBFDE}</Project>
<Name>Billing.Reports</Name>
</ProjectReference>
<ProjectReference Include="..\Csla\Csla.Net4\Csla.Net4.csproj">
<Project>{1FCE45FF-C391-4ED1-A9C4-F71CAF8773E6}</Project>
<Name>Csla.Net4</Name>
</ProjectReference>
<ProjectReference Include="..\Ref4.csproj">
<Project>{3972242B-DF6A-4B9B-9121-6138090CA114}</Project>
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Thanks in advance for any answers/suggestions.

Figured it out. Apparently I was missing a reference that was unbeknownst to me. All the other projects were referencing Microsoft's BCL Portability Pack. Once I saw that in NuGet and all projects had it except the new one, I immediately referenced it and now everything builds.
That was a fun ghost hunt.

Another reason for this annoying error. Found this by looking at the warning messages. The error messages on build did not give the needed info:
Warning 6 The primary reference "C:..path-to-you-solution-ref.dll"
could not be resolved because it was built against the
".NETFramework,Version=v4.5.1" framework. This is a higher version
than the currently targeted framework ".NETFramework,Version=v4.5".
Being I'm on a clean install of VStudio, looks like the default project is not set yet to the higher version as I had it. So a version disparity (referencing a higher version from a lower one) will do this.

Related

Why would NET6_0_WINDOWS be undefined in a Net6.0-windows project?

I have a legacy program I'm trying to migrate from Net Framework 4.6.1 to .NET 6. In it, there's a shared library which needs to run on Linux as well as Windows, with some Windows-specific calls which I've successfully sequestered using #if NET6_0_WINDOWS. This was enough to get the Linux version up and running, but when I tried to add in the Windows WPF App, I got thousands of errors.
To bring the WPF app up to date, I ran the upgrade assistant (which is detailed here). Unfortunately, the app wouldn't compile without considerable effort.
I set my project files in the UI to explicitly target windows (using net6.0-windows as the TargetFramework) and my xaml files won't associate with the code (this is a common problem with LOTS of potential causes which I'm separately investigating using the thread here. For instance, I get errors on InitializeComponent where the compiler can't find it, as well as the errors mentioned in the thread.
To make things even stranger, when I run the app (after a lot of #if NET6_0_WINDOWS tweaking), I can't set breakpoints in the code in the #if'd blocks... I may be going down a rabbit trail, but why would that symbol be undefined?
In case it's relevant, the project file for the WPF app that's running looks like the following:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>WPFApp</RootNamespace>
<ApplicationIcon>SoftingIcon.ico</ApplicationIcon>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<OutputPath>..\bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>..\bin\Release\</OutputPath>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<OutputPath>..\bin\Release\</OutputPath>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup>
<NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup>
<ItemGroup>
<Reference Update="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Update="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Update="UIAutomationProvider">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\EditModel\EditModel.csproj" />
<ProjectReference Include="..\..\common\Tools\Tools.csproj" />
<ProjectReference Include="..\Help\HelpInterface\HelpInterface.csproj" />
<ProjectReference Include="..\ViewPaneLibrary\ViewPaneLibrary.csproj" />
<ProjectReference Include="..\InterfaceControls\InterfaceControls.csproj" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
</Project>
The preprocessor symbol only includes the .Net version, not the OS (also be careful, there is no underscore between NET and 6).
A full list of the symbols can be found here:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives
However, you can define it yourself in MSBuild.
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
<DefineConstants>$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
</PropertyGroup>

Multi-targeted UWP project can't refer .NET Standard 2.0 project

I have a multi-targeted project (MultiTargetedProj) that targets .NET Standard 2.0 and UWP. This project refers a .NET Standard 2.0 project (SayClassLibraryProj).
When building MultiTargetedProj, I get an error saying ClassLibraryProj's dll cannot be found:
7>CSC : error CS0006: Metadata file 'C:\Users\sanjay\Downloads\NewProjectStructurePOC-master(2)\NewProjectStructurePOC-master\ClassLibraryProj\bin\x64\Debug\uap10.0\ClassLibraryProj.dll' could not be found
7>Done building project "MultiTargetedProj.csproj" -- FAILED.
As per my understanding, ClassLibraryProj's bin should only have a sub folder for .NET Standard and not for UWP. Since my reference to ClassLibraryProj is non-conditional, multi targeted project should resolve correctly.
When I replace project references with direct DLL reference to the .NET Standard subfolder, the build succeeds.
Project configuration for MultiTargetedProj:
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;uap10.0</TargetFrameworks>
<AssemblyName>MultiTargetedProj</AssemblyName>
<RootNamespace>MultiTargetedProj</RootNamespace>
<Platforms>AnyCPU;x64;x86</Platforms>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<BaseOutputPath></BaseOutputPath>
<BaseIntermediateOutputPath></BaseIntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<!--<Reference Include="..\ClassLibraryProj\bin\x64\Debug\netstandard2.0\ClassLibraryProj.dll" />-->
<ProjectReference Include="..\ClassLibraryProj\ClassLibraryProj.csproj" />
</ItemGroup>
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcore')) ">
<DefineConstants>NET_CORE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" $(TargetFramework.StartsWith('uap')) ">
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0 .18362.0</TargetPlatformMinVersion>
<DefineConstants>WINDOWS_UWP</DefineConstants>
<LanguageTargets>$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets</LanguageTargets>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Remove="obj\**" />
<None Remove="obj\**" />
</ItemGroup>
<ItemGroup>
...
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('uap')) ">
<Compile Include="UWP\**\*.cs" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.13</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('netcore')) ">
<Compile Include="NetCore\**\*.cs" />
</ItemGroup>
</Project>
This issue is only while using.NET SDK Version 6.0.302. On a different machine with .NET SDK Version 5.0.410, build succeeds.

Github action nuget restore .NET 4.7.2

I have a .net framework C# project targetting .net 4.7.2 and I'm trying to do a nuget restore and build using a github action.
I'm getting the following error on nuget restore:
Run nuget restore SAPtoAPLv3Check/SAPtoAPLv3Check.csproj
MSBuild auto-detection: using msbuild version '16.11.0.36601' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin'.
Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
Error: Process completed with exit code 1.
My github action looks like this:
name: Release
on:
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code.
uses: actions/checkout#v2
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 5.0.x
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild#v1.0.2
- name: Setup Nuget
uses: Nuget/setup-nuget#v1.0.5
- name: Restore nuget packages
run: nuget restore SAPtoAPLv3Check/SAPtoAPLv3Check.csproj
- name: Build
run: msbuild SAPtoAPLv3Check/SAPtoAPLv3Check.csproj /p:Configuration=Release
I have other github actions building later .net framework versions, and restoring nugets, fine. Mainly those targeting .netcore and .net48x.
Where I should specify the folder for nuget?
nuget restore -OutputDirectory "????" SAPtoAPLv3Check/SAPtoAPLv3Check.csproj
My .csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{BF3CB6D2-503F-4ED9-96E6-6D5DD50EA201}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SAPtoAPLv3Check</RootNamespace>
<AssemblyName>SAPtoAPLv3Check</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<ItemGroup>
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Dapper.2.0.90\lib\net461\Dapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c">
<HintPath>..\packages\NLog.5.0.0-preview.1\lib\net46\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SentilanAgent.MessageV1, Version=1.2.7912.29046, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\SentilanAgent.MessageV1.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QueryRow.cs" />
<Compile Include="ServerAndDatabase.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="databases.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Lib\SentilanAgent.MessageV1.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
What I don't have is a packages.config, is this what I'm missing. Adding the nugets via Rider didn't generate one.
I pointed the nuget restore at the .sln file rather than the .csproj and it worked.

'HttpClientHandler' does not contain a definition for 'ClientCertificates' in net461 and net47?

I'm making a NuGet package and my csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.6;net461;net47</TargetFrameworks>
...
<PackageId>Package2</PackageId>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Package1\Package1.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
The project it's referencing looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.6;net461;net47</TargetFrameworks>
<PackageId>Package1</PackageId>
...
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<NoWarn>1701;1702; CS1591</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6' OR '$(TargetFramework)'=='net461'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
And inside the Package2 project it has the following line:
webRequestHandler.ClientCertificates.Add(certificate);
But it isn't building in net461 or net47, saying:
'HttpClientHandler' does not contain a definition for
'ClientCertificates' and no accessible extension method
'ClientCertificates' accepting a first argument of type
'HttpClientHandler' could be found (are you missing a using
directive or an assembly reference?)
Package2(net461),
Package2(net47)
But the only thing I've changed is removed this from the csproj for package2:
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6' OR '$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" />
</ItemGroup>
Can anyone help me understand how to fix it? I don't really want to bring in that whole NuGet package just to fix this one dependency I think I'm just missing an assembly but as far as I know it should be in System.Net.Http which I should already be referencing (and so should the other project it's already dependent on).
Looks like this property is available from version 4.7.1:
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.clientcertificates?view=netframework-4.7.1
Note that if you select an older .NET version, you'll see a message like this:
The requested page is not available for .NET Framework 4.7.
For me the solution was to download the newest version of "System.Net.Http".
You can find it through the NuGet package manager.
At the time of writing v4.3.4 is the newest version and it contains the ClientCertificates methode.
I've swapped out the assembly reference for the NuGet package:
<ItemGroup Condition="'$(TargetFramework)'=='net47' OR '$(TargetFramework)'=='net461'">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
pretty sure this is the wrong thing to do™ as the assembly reference in .NET Framework should be sufficient and I'm probably going to suffer many conflicting reference issues anywhere I install my package, but this is the best I can come up with right now.

VSCode c# add reference to custom assembly

in Visual Studio Code I simply want to add a reference
to an custom c# assembly like
"../libs/mylib.dll"
how can I add this dependency?
I tried to add the path to the dependency but was not able to compile because its just wrong :)
"dependencies": {
"myassembly" : "../libs/Common.dll"
},
or
"dependencies": {
"log4net" : { "assembly":"../libs/log4net.dll" }
},
simpler, just add the following:
1) modify the myproject.csproj file
<ItemGroup>
<Reference Include="DllComunVb2008">
<HintPath>..\Dlls\DllComunVb2008.dll</HintPath>
</Reference>
</ItemGroup>
2) Add the using of the library you are going to use. Example: using Dllcomun;
I finally found a way to reference any .net assembly within visual studio code.
First to note: I only need the vscode for the intellisense. I will not compile the assembly in vscode /.netcore.
When I'm done with coding, I will use commandline-tools to generate my assembly.
And this is my solution:
Create an regular .net class library with Visual studio (not code)
This will create an myproject.csproj-file (wich can be read by vscode).
Or use my test.csproj-file at the bottom of the post.
create an folder for the referenced assemblies. I've just created an libs-directory inside the top-directory.
close vs and open the folder with vscode.
modify the *.csproj-file as followed:
note: we've created the project in debug-mode, so we can remove the release-property-group:
4.2. remove the Release-PropertyGroup (you don't have to, but you don't need it)
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
4.3. Modify the bin-output-path to the libs-directory
from
<OutputPath>bin\Debug\</OutputPath>
to
<OutputPath>libs</OutputPath>
4.4. put your referencing .net assembly (external or custom) in the libs-directory and references them like:
...
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
...
</ItemGroup>
...
this is the complete *.csproj file with reference to an log4net.dll.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{75278D05-4850-4282-8AB4-3643A9E799FF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>libs</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="myassembly.cs" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
I create a project with dotnet and then open it with Visual Studio 2019. Then click project, Add reference, browse to Dll, then save project (save a solution incase you want to open it again with file)
Now open it with vscode.

Categories

Resources