Can I migrate this old csproj to VS2017 csproj? - c#

I want to simplify my PCL csproj and I can't seem to find the appropriate TargetFrameworks..
This is my old csproj:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D035A2E6-EF3E-4F50-B6D7-396F83FE313F}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>PCL.Acme</RootNamespace>
<AssemblyName>PCL.Acme</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile151</TargetFrameworkProfile>
</PropertyGroup>
The current nuget has a framework folder formatted like portable46-net451%2Bwin81%2Bwpa81.
I cannot target netstandard1.2 because I have a dependency on another PCL...
Any help is appreciated.
Update
This csproj format made it possible to reference my old PCL nuget package.
Now I can start migrating the PCL.Acme.Another.Library project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.2</TargetFrameworks>
<PackageId>PCL.Acme</PackageId>
<Authors>Acme</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTargetFallback>
$(PackageTargetFallback);portable46-net451+win81+wpa81
</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PCL.Acme.Another.Library" Version="1.0.0" />
</ItemGroup>
</Project>

I would recreate csproj (start over) with new format it's much easier. This blog post is really helpful https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/
Edit: all supported target frameworks https://learn.microsoft.com/en-us/dotnet/standard/frameworks
Edit2:
<PackageTargetFallback>
$(PackageTargetFallback);portable-net45+win8+wpa81+wp8
</PackageTargetFallback>
Might help as well. More info here https://learn.microsoft.com/en-us/dotnet/core/tools/csproj
If link goes down
Class library
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
</Project>
Console app
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
</Project>
Test project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
</Project>

Related

Problem with run net core app on Ubuntu 16.08

I am trying to start a chat bot written in net core 2.1 on a Ubuntu 2.1 machine. But the application does not want to start on the following problem:
This is what my csproj file looks like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
<TargetFramework>netcoreapp2.1</TargetFramework>
<StartupObject></StartupObject>
<ApplicationIcon />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Net.Code.ADONet" Version="4.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.111" />
<PackageReference Include="xNet" Version="3.3.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
</ItemGroup>
</Project>
Fixed the problem.
I used "publishing" through a visual studio, and this caused this problem.
Using the dotnet console solves this problem.

DotNet Core 3.1 - Multiple projects with shared src, obj and bin

I have the following folder structure (following the feature-oriented organization):
Solution
bin
obj
src
Module1
Shared.cs
Module2
Shared.cs
Module3
Shared.cs
Server
Program.cs
Startup.cs
Database
Program.cs
Solution.sln
Server.csproj
Database.csproj
For the Server project I am using Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web for the Database.
Here is the actual Server.csproj:
<Project>
<PropertyGroup>
<TargetFramework>NetCoreApp3.1</TargetFramework>
<Configuration Condition=" '$(Configuration)' == '' ">Development</Configuration>
<EnvironmentName>$(Configuration)</EnvironmentName>
<BaseOutputPath>bin/$(MSBuildProjectName)</BaseOutputPath>
<OutputPath>$(BaseOutputPath)/$(Configuration)</OutputPath>
<BaseIntermediateOutputPath>obj/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>False</AppendRuntimeIdentifierToOutputPath>
<EnableDefaultContentItems>False</EnableDefaultContentItems>
<Nullable>Enable</Nullable>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RootNamespace>OeMis.Server</RootNamespace>
<StartupObject>OeMis.Server.ServerEntry</StartupObject>
</PropertyGroup>
<ItemGroup>
<Content Include="Configuration.$(Configuration).json" ExcludeFromSingleFile="True" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest"/>
<PackageReference Include="Dapper" Version="2.0.30"/>
<PackageReference Include="HotChocolate" Version="11.0.0-preview.95"/>
<PackageReference Include="HotChocolate.AspNetCore" Version="11.0.0-preview.95"/>
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="11.0.0-preview.95"/>
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="11.0.0-preview.95"/>
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0-preview1.20021.1"/>
</ItemGroup>
<Import Sdk="Microsoft.NET.Sdk.Web" Project="Sdk.props"/>
<Import Sdk="Microsoft.NET.Sdk.Web" Project="Sdk.targets"/>
</Project>
And here is the Database.csproj:
<Project>
<PropertyGroup>
<TargetFramework>NetCoreApp3.1</TargetFramework>
<Configuration Condition=" '$(Configuration)' == '' ">Development</Configuration>
<EnvironmentName>$(Configuration)</EnvironmentName>
<OutputType>Exe</OutputType>
<BaseOutputPath>bin/$(MSBuildProjectName)</BaseOutputPath>
<OutputPath>$(BaseOutputPath)/$(Configuration)</OutputPath>
<BaseIntermediateOutputPath>obj/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>False</AppendRuntimeIdentifierToOutputPath>
<EnableDefaultContentItems>False</EnableDefaultContentItems>
<Nullable>Enable</Nullable>
<RootNamespace>OeMis.Database</RootNamespace>
<StartupObject>OeMis.Database.DatabaseEntry</StartupObject>
</PropertyGroup>
<ItemGroup>
<Content Include="Configuration.$(Configuration).json" ExcludeFromSingleFile="True" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest"/>
<PackageReference Include="Dapper" Version="2.0.30"/>
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0-preview1.20021.1"/>
<PackageReference Include="Bogus" Version="29.0.1"/>
</ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props"/>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets"/>
</Project>
I always get errors in src/Server/Program.cs as if Database.csproj is trying to handle it. The errors have to do with missing references classes in Microsoft.NET.Sdk.Web.
The full project can be found on GitHub
This actually makes sense. You are trying to build the same source files with different dependencies.
My advise is to extract the common/shared items from both and add the to a new project called shared (preferable in .Net standard) and reference the libraries in both your projects.
Creating a class library for .net core guide here
TL;DL;
Create a Solution and Client App.
Create a Class Library Project.
Add Class Library Functionality.
Settings.
Build.
Add Class Library Reference.
Import Namespace.
Call Functions.

Deploy click-once application with Azure Devops?

I have an error when deploying my click-once project with Azure DevOps Pipeline. I don't see where is my error.
First, I can build and publish my click-once application manually from Visual Studio. I have no issue.
When I use Azure DevOps Pipeline to build and publish my click-once application I get an error:
[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(780,5):
Error : The OutputPath property is not set for project
'******.vbproj'. Please check to make sure that you have specified a
valid combination of Configuration and Platform for this project.
Configuration='release' Platform='any cpu'. You may be seeing this
message because you are trying to build a project without a solution
file, and have specified a non-default Configuration or Platform that
doesn't exist for this project.
The OutputPath property is not set for project. Well, I don't know. Let me give you my project file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>{****}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>****.*****4</RootNamespace>
<AssemblyName>****.*****4</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>true</IsWebBootstrapper>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
<PublishFilePath>$(PublishDir)install*****4.html</PublishFilePath>
<PublishUrl>\\server15\c%24\inetpub\wwwroot\*****4Install %28Staging%29\</PublishUrl>
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>true</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>http://*****4install-staging.newsprintgroup.com/</InstallUrl>
<ProductName>***** Application</ProductName>
<PublisherName>NewsPrint Group</PublisherName>
<MinimumRequiredVersion>4.15.0.0</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>install*****4.html</WebPage>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>4.15.9.1</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</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>
<PropertyGroup>
<ManifestCertificateThumbprint>57DF31CB3510678332744572F14AD9BAAC60178E</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>****.*****4_1_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
(...)
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
<Error Condition="!Exists('..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets'))" />
</Target>
<Import Project="..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets" Condition="Exists('..\packages\SlowCheetah.2.5.48\build\SlowCheetah.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>
This error only relevant with your incorrect configuration about the Platform in the
task. It should caused by the value you specified to Platform could not be recognized by the task. Without the Platform value, the server prompt the error message Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.
Since what you used in the task is .*proj file instead of .sln file, to solve the error you are facing, here you need use AnyCPU rather than a normal value any cpu.
In this doc, it point out that corresponding to different file designation methods, you should use the different task configurations:

Class project why need add 『Microsoft.AspNetCore.MVC』 ProjectReference in aspnetcore2.2 if already included 『Microsoft.AspNetCore.App 2.2.0』

c# - aspnetcore web project import another project's controller - Stack Overflow
two project's csproj and version :
AspNetCore Web Project
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Controller\Controller.csproj" />
</ItemGroup>
</Project>
Controller Project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
</Project>
Controller Project Code
using Microsoft.AspNetCore.Mvc;
public class HomeController : Controller
{
public IActionResult Index()
{
return Content("Hello S.O");
}
}
Question
if run AspNetCore Web Project it'll get HTTP ERROR 404.
I need to add <PackageReference Include="Microsoft.AspNetCore.MVC"/> in cspoj
to run successfully.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.AspNetCore.MVC" />
</ItemGroup>
</Project>
But Isn't NuGet | Microsoft.AspNetCore.App 2.2.0 already included Microsoft.AspNetCore.MVC,Why i need to add again?

Build C# standard project with the latest versions of the nuget references

When using new C# projects we don't have packages.config files. The dependencies are specified inside the *.proj file, something like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="XYZ.Definitions" Version="1.0.0-CI-20181010-102209" />
<PackageReference Include="XYZ.Definitions.Common" Version="1.0.0-CI-20181010-102209" />
</ItemGroup>
</Project>
How can I specify that I always want to build with the latest versions available of my references?
I was thinking something like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="XYZ.Definitions" Version="latest" />
<PackageReference Include="XYZ.Definitions.Common" Version="latest" />
</ItemGroup>
</Project>
I dont know if this is even possible.
Also here you can find a solution but in another context, that is using packages.config and nuget.config files.
* will use the latest stable version available.
Solution:
<PackageReference Include="XYZ.Definitions" Version="*" />

Categories