I have a solution with multiple projects. Most are libraries except for two that are EXE projects.
I wanted to share assembly information in a file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<BaseNamespace>Shared.Namespace</BaseNamespace>
<Company>My company</Company>
<Authors>Author's name</Authors>
<Copyright>$(Company)</Copyright>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>$(BaseNamespace).$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>
</Project>
That I import in the projects using <Import Project="..\ProjectsCommon.props" />
. The properties are well propagated and can be overridden, except for OutputType
.
The EXE projects are considered as Library ones. If I set the output type in the props file to EXE, then all projects are compiled as EXE (which creates errors due to missing Main).
Here is the real project commit that I am talking about: https://github.com/CyberInternauts/CmdStarter/commit/5ef693de1e2fd220f820ea4439bcb33a949fca0b
Only two things to look:
.props
file.Demo.csproj
fileAny ideas?
The problem is the Sdk
attribute on the project element, it will add an implicit import, this results in a conflict to the import in the csproj file.
Removing it from the .props file will solve your problem.
<Project>
<PropertyGroup>
<BaseNamespace>Shared.Namespace</BaseNamespace>
<Company>My company</Company>
<Authors>Author's name</Authors>
<Copyright>$(Company)</Copyright>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>$(BaseNamespace).$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>
</Project>