Skip to content

Latest commit

 

History

History
196 lines (150 loc) · 4.3 KB

netcore-csproj.md

File metadata and controls

196 lines (150 loc) · 4.3 KB

netcore csproj


generate documentation

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>    
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
</Project>

to disable warn about missing doc

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>    
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <noWarn>1591</noWarn>
  </PropertyGroup>
</Project>

copy to output folder

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
  <None Include="doc/file.dxf" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
  • to be recursive ( sparse files in output )
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
  <None Include="doc/**/*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
  • to be recursive ( single folder in output )
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
  <None Include="doc/**/*" CopyToOutputDirectory="PreserveNewest" Link="doc/%(RecursiveDir)/%(Filename)%(Extension)" />
</ItemGroup>
  • to include in aspnet core publish
<ItemGroup>
    <Content Include="somefld/subfld/**">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemGroup>

csharp macro define csproj

to define a constant to use in the code like this

#if MYCONST
//
#else
//
#endif

edit .csproj like follow ( separate by semicolon )

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <DefineConstants>MYCONST;MYCONST2</DefineConstants>  
  </PropertyGroup>
</Project>

or conditionally based on configuration used dotnet build -c Release

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <DefineConstants>MYCONST;MYCONST2</DefineConstants>  
  </PropertyGroup>  
</Project>

platform macro

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
    <DefineConstants>WINDOWS_PLATFORM</DefineConstants>  
  </PropertyGroup>  

  <PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
    <DefineConstants>OSX_PLATFORM</DefineConstants>  
  </PropertyGroup>  

  <PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
    <DefineConstants>LINUX_PLATFORM</DefineConstants>  
  </PropertyGroup>
</Project>

the use in code like follow

#if WINDOWS_PLATFORM
//
#else
//
#endif

exclude files from compile

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RootNamespace>server_lib</RootNamespace>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>    
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Program.cs"/>
  </ItemGroup>

</Project>

disable warnings

follow to disable missing XML comment

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <noWarn>1591</noWarn>
    </PropertyGroup>
</Project>

force bin,obj clean

⚠️ this will remove all bin and obj folders recursively starting from current working dir

 find -type d -name "bin" -exec rm -fr '{}' \; ; find -type d -name "obj" -exec rm -fr '{}' \;

execute cmd before build

<Target Name="MyPreBuildTarget" BeforeTargets="Build">
  <Exec Command="echo sample"/>
</Target>

link source from other project

<ItemGroup>
  <Compile Include="../iot-gateway-api/IOTGateway.cs"/>
</ItemGroup>

prebuild copy files

follow task will copy a file placed ( relative to csproj ) ../../src/gui/Assets/Dictionary1.xaml into the csproj folder base relative Assets/gui before each build

<Target Name="CopyGUIAssets" BeforeTargets="Build">
  <Copy SourceFiles="../../src/gui/Assets/Dictionary1.xaml" DestinationFolder="Assets/gui" />
</Target>