← all demos
// ***********************************************************************************************
// Microsoft.CSharp.CurrentVersion.targets
//
// WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
// created a backup copy.  Incorrect changes to this file will make it
// impossible to load or build your projects from the command-line or the IDE.
//
// This file defines the steps in the standard build process specific for C# .NET projects.
// For example, it contains the step that actually calls the C# compiler.  The remainder
// of the build process is defined in Microsoft.Common.targets, which is imported by
// this file.
//
// Copyright (C) Microsoft Corporation. All rights reserved.
// ***********************************************************************************************
Project
  PropertyGroup
    if '$(ImportByWildcardBeforeMicrosoftCSharpTargets)' == '':
      ImportByWildcardBeforeMicrosoftCSharpTargets = true
    if '$(ImportByWildcardAfterMicrosoftCSharpTargets)' == '':
      ImportByWildcardAfterMicrosoftCSharpTargets = true
    if '$(ImportUserLocationsByWildcardBeforeMicrosoftCSharpTargets)' == '':
      ImportUserLocationsByWildcardBeforeMicrosoftCSharpTargets = true
    if '$(ImportUserLocationsByWildcardAfterMicrosoftCSharpTargets)' == '':
      ImportUserLocationsByWildcardAfterMicrosoftCSharpTargets = true
  if '$(ImportUserLocationsByWildcardBeforeMicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportBefore'):
    Import "$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportBefore\*"
  if '$(ImportByWildcardBeforeMicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportBefore'):
    Import "$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportBefore\*"
  PropertyGroup
    if '$(CustomBeforeMicrosoftCSharpTargets)'=='':
      CustomBeforeMicrosoftCSharpTargets = $(MSBuildExtensionsPath)\v$(MSBuildToolsVersion)\Custom.Before.Microsoft.CSharp.targets
    if '$(CustomAfterMicrosoftCSharpTargets)'=='':
      CustomAfterMicrosoftCSharpTargets = $(MSBuildExtensionsPath)\v$(MSBuildToolsVersion)\Custom.After.Microsoft.CSharp.targets
  if '$(CustomBeforeMicrosoftCSharpTargets)' != '' and Exists('$(CustomBeforeMicrosoftCSharpTargets)'):
    Import "$(CustomBeforeMicrosoftCSharpTargets)"
  PropertyGroup
    DefaultLanguageSourceExtension = .cs
    Language = C#
    TargetRuntime = Managed
    AlwaysUseNumericalSuffixInItemNames = true
    if '$(DefineCommonItemSchemas)' == '':
      DefineCommonItemSchemas = true
    if '$(DefineCommonReferenceSchemas)' == '':
      DefineCommonReferenceSchemas = true
    if '$(DefineCommonCapabilities)' == '':
      DefineCommonCapabilities = true
    if '$(SynthesizeLinkMetadata)' == '' and '$(HasSharedItems)' == 'true':
      SynthesizeLinkMetadata = true
    if '$(DefaultProjectTypeGuid)' == '':
      DefaultProjectTypeGuid = {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
    if '$(AppDesignerFolder)' == '':
      AppDesignerFolder = Properties
  if '$(DefineCSharpItemSchemas)' != 'false':
    ItemGroup
      PropertyPageSchema += "$(CommonXamlResourcesDirectory)CSharp.ProjectItemsSchema.xaml;"
      PropertyPageSchema += "$(CommonXamlResourcesDirectory)CSharp.xaml;"
        Context = File
      PropertyPageSchema += "$(CommonXamlResourcesDirectory)CSharp.BrowseObject.xaml;"
        Context = BrowseObject
      ProjectCapability += "CSharp;Managed"
  if '$(DefineCommonCapabilities)' == 'true':
    ItemGroup
      ProjectCapability += "ReferencesFolder;LanguageService"
  // The CreateManifestResourceNames target create the manifest resource names from the .RESX
  // files.
  //
  // [IN]
  // @(EmbeddedResource) - The list of EmbeddedResource items that have been pre-processed to add metadata about resource type
  // Expected Metadata "Type" can either be "Resx" or "Non-Resx"
  //
  // [OUT]
  // @(EmbeddedResource) - EmbeddedResource items with metadata
  //
  // For C# applications the transformation is like:
  //
  // Resources1.resx => RootNamespace.Resources1 => Build into main assembly
  // SubFolder\Resources1.resx => RootNamespace.SubFolder.Resources1 => Build into main assembly
  // Resources1.fr.resx => RootNamespace.Resources1.fr => Build into satellite assembly
  // Resources1.notaculture.resx => RootNamespace.Resources1.notaculture => Build into main assembly
  //
  // For other project systems, this transformation may be different.
  PropertyGroup
    CreateManifestResourceNamesDependsOn
  if '@(EmbeddedResource)' != '':
    Target CreateManifestResourceNames(DependsOnTargets="$(CreateManifestResourceNamesDependsOn)")
      ItemGroup
        _Temporary -= "@(_Temporary)"
      // Create manifest names for culture and non-culture Resx files, and for non-culture Non-Resx resources
      if '%(EmbeddedResource.ManifestResourceName)' == '' and ('%(EmbeddedResource.WithCulture)' == 'false' or '%(EmbeddedResource.Type)' == 'Resx'):
        CreateCSharpManifestResourceName(
            EnableCustomCulture="$(EnableCustomCulture)",
            ResourceFiles="@(EmbeddedResource)",
            RootNamespace="$(RootNamespace)",
            UseDependentUponConvention="$(EmbeddedResourceUseDependentUponConvention)")
          Output(ItemName="_Temporary", TaskParameter="ResourceFilesWithManifestResourceNames")
      // Create manifest names for all culture non-resx resources
      if '%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx':
        CreateCSharpManifestResourceName(
            PrependCultureAsDirectory="false",
            ResourceFiles="@(EmbeddedResource)",
            RootNamespace="$(RootNamespace)",
            UseDependentUponConvention="$(EmbeddedResourceUseDependentUponConvention)")
          Output(ItemName="_Temporary", TaskParameter="ResourceFilesWithManifestResourceNames")
      ItemGroup
        if '%(EmbeddedResource.ManifestResourceName)' == '':
          EmbeddedResource -= "@(EmbeddedResource)"
        EmbeddedResource += "@(_Temporary)"
        _Temporary -= "@(_Temporary)"
  if '$(CodeAnalysisRuleSet)' != '':
    Target ResolveCodeAnalysisRuleSet
      ResolveCodeAnalysisRuleSet(
          CodeAnalysisRuleSet="$(CodeAnalysisRuleSet)",
          CodeAnalysisRuleSetDirectories="$(CodeAnalysisRuleSetDirectories)",
          MSBuildProjectDirectory="$(MSBuildProjectDirectory)")
        Output(
            PropertyName="ResolvedCodeAnalysisRuleSet",
            TaskParameter="ResolvedCodeAnalysisRuleSet")
  ItemGroup
    // Activate CPS projects to track folder names in namespace.
    ProjectCapability += "RelativePathDerivedDefaultNamespace"
  PropertyGroup
    // Provide a facility to override UseHostCompilerIfAvailable
    if '$(UseHostCompilerIfAvailable)' == '':
      UseHostCompilerIfAvailable = true
  ItemGroup
    if '$(DocumentationFile)'!='':
      DocFileItem += "$(DocumentationFile)"
  if '$(_DebugSymbolsProduced)' == 'true' and '$(PdbFile)' != '':
    ItemGroup
      _DebugSymbolsIntermediatePathTemporary += "$(PdbFile)"
      // Add any missing .pdb extension, as the compiler does
      _DebugSymbolsIntermediatePath += "@(_DebugSymbolsIntermediatePathTemporary->'%(RootDir)%(Directory)%(Filename).pdb')"
  PropertyGroup
    CoreCompileDependsOn = $(CoreCompileDependsOn);_ComputeNonExistentFileProperty;ResolveCodeAnalysisRuleSet
    if '$(ExportWinMDFile)' == '' and '$(OutputType)' == 'WinMDObj':
      ExportWinMDFile = true
  // The XamlPreCompile target must remain identical to
  // the CoreCompile target in Microsoft.CSharp.Core.targets,
  // except that GeneratedFilesOutputPath is intentionally omitted.
  // Any updates to one must be made to the other.
  if '@(Page)' != '' Or '@(ApplicationDefinition)' != '':
    Target XamlPreCompile(
        DependsOnTargets=[
          $(CoreCompileDependsOn)
          GenerateMSBuildEditorConfigFile
        ],
        Inputs="$(MSBuildAllProjects);
                @(Compile);
                @(_CoreCompileResourceInputs);
                $(ApplicationIcon);
                $(AssemblyOriginatorKeyFile);
                @(ReferencePath);
                @(CompiledLicenseFile);
                @(LinkResource);
                @(EmbeddedDocumentation);
                $(Win32Resource);
                $(Win32Manifest);
                @(CustomAdditionalCompileInputs);
                @(Page);
                @(ApplicationDefinition);
                $(ResolvedCodeAnalysisRuleSet)",
        Outputs="@(DocFileItem);
                 @(XamlIntermediateAssembly);
                 @(_DebugSymbolsIntermediatePath);
                 $(NonExistentFile);
                 @(CustomAdditionalCompileOutputs)",
        Returns="")
      // These two compiler warnings are raised when a reference is bound to a different version
      // than specified in the assembly reference version number.  MSBuild raises the same warning in this case,
      // so the compiler warning would be redundant.
      if ('$(TargetFrameworkVersion)' != 'v1.0') and ('$(TargetFrameworkVersion)' != 'v1.1'):
        PropertyGroup
          NoWarn = $(NoWarn);1701;1702
      PropertyGroup
        // To match historical behavior, when inside VS11+ disable the warning from csc.exe indicating that no sources were passed in
        if '$(BuildingInsideVisualStudio)' == 'true' and '$(VisualStudioVersion)' != '' and '$(VisualStudioVersion)' > '10.0':
          NoWarn = $(NoWarn);2008
      if '$(TargetingClr2Framework)'=='true':
        ItemGroup
          ReferencePath
            EmbedInteropTypes
      PropertyGroup
        // If the user has specified AppConfigForCompiler, we'll use it. If they have not, but they set UseAppConfigForCompiler,
        // then we'll use AppConfig
        if '$(AppConfigForCompiler)' == '' and '$(UseAppConfigForCompiler)' == 'true':
          AppConfigForCompiler = $(AppConfig)
        // If we are targeting winmdobj we want to specifically the pdbFile property since we do not want it to collide with the output of winmdexp
        if '$(PdbFile)' == '' and '$(OutputType)' == 'winmdobj' and '$(_DebugSymbolsProduced)' == 'true':
          PdbFile = $(IntermediateOutputPath)$(TargetName).compile.pdb
      // Prefer32Bit was introduced in .NET 4.5. Set it to false if we are targeting 4.0
      if ('$(TargetFrameworkVersion)' == 'v4.0'):
        PropertyGroup
          Prefer32Bit = false
      if ('$(AdditionalFileItemNames)' != ''):
        ItemGroup
          AdditionalFileItems += "$(AdditionalFileItemNames)"
          AdditionalFiles += "@(%(AdditionalFileItems.Identity))"
      if '$(UseSharedCompilation)' == '':
        PropertyGroup
          UseSharedCompilation = true
      // Condition is to filter out the _CoreCompileResourceInputs so that it doesn't pass in culture resources to the compiler
      // Don't run analyzers for Csc task on XamlPrecompile pass, we only want to run them on core compile.
      if '%(_CoreCompileResourceInputs.WithCulture)' != 'true':
        Csc(
            AddModules="@(AddModules)",
            AdditionalFiles="@(AdditionalFiles)",
            AdditionalLibPaths="$(AdditionalLibPaths)",
            AllowUnsafeBlocks="$(AllowUnsafeBlocks)",
            AnalyzerConfigFiles="@(EditorConfigFiles)",
            Analyzers="@(Analyzer)",
            ApplicationConfiguration="$(AppConfigForCompiler)",
            BaseAddress="$(BaseAddress)",
            CheckForOverflowUnderflow="$(CheckForOverflowUnderflow)",
            ChecksumAlgorithm="$(ChecksumAlgorithm)",
            CodeAnalysisRuleSet="$(ResolvedCodeAnalysisRuleSet)",
            CodePage="$(CodePage)",
            CompilerType="$(RoslynCompilerType)",
            DebugType="none",
            DefineConstants="$(DefineConstants)",
            DelaySign="$(DelaySign)",
            Deterministic="$(Deterministic)",
            DisableSdkPath="$(DisableSdkPath)",
            DisabledWarnings="$(NoWarn)",
            DocumentationFile="@(DocFileItem)",
            EmbedAllSources="false",
            EmbeddedFiles="@(EmbeddedFiles)",
            EmitDebugInformation="$(DebugSymbols)",
            EnvironmentVariables="$(CscEnvironment)",
            ErrorEndLocation="$(ErrorEndLocation)",
            ErrorLog="$(ErrorLog)",
            ErrorReport="$(ErrorReport)",
            Features="$(Features)",
            FileAlignment="$(FileAlignment)",
            GenerateFullPaths="$(GenerateFullPaths)",
            HighEntropyVA="$(HighEntropyVA)",
            Instrument="$(Instrument)",
            InterceptorsNamespaces="$(InterceptorsNamespaces)",
            InterceptorsPreviewNamespaces="$(InterceptorsPreviewNamespaces)",
            KeyContainer="$(KeyContainerName)",
            KeyFile="$(KeyOriginatorFile)",
            LangVersion="$(LangVersion)",
            LinkResources="@(LinkResource)",
            MainEntryPoint="$(StartupObject)",
            ModuleAssemblyName="$(ModuleAssemblyName)",
            NoConfig="true",
            NoLogo="$(NoLogo)",
            NoStandardLib="$(NoCompilerStandardLib)",
            NoWin32Manifest="$(NoWin32Manifest)",
            Nullable="$(Nullable)",
            Optimize="$(Optimize)",
            OutputAssembly="@(XamlIntermediateAssembly)",
            PathMap="$(PathMap)",
            Platform="$(PlatformTarget)",
            Prefer32Bit="$(Prefer32Bit)",
            PreferredUILang="$(PreferredUILang)",
            ProjectName="$(MSBuildProjectName)",
            ProvideCommandLineArgs="$(ProvideCommandLineArgs)",
            PublicSign="$(PublicSign)",
            RefOnly="false",
            References="@(ReferencePath)",
            ReportAnalyzer="$(ReportAnalyzer)",
            ReportIVTs="$(ReportIVTs)",
            Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)",
            ResponseFiles="$(CompilerResponseFile)",
            RuntimeMetadataVersion="$(RuntimeMetadataVersion)",
            SharedCompilationId="$(SharedCompilationId)",
            SkipAnalyzers="true",
            SkipCompilerExecution="$(SkipCompilerExecution)",
            SourceLink="$(SourceLink)",
            Sources="@(Compile)",
            SubsystemVersion="$(SubsystemVersion)",
            TargetFramework="$(TargetFramework)",
            TargetType="$(OutputType)",
            ToolExe="$(CscToolExe)",
            ToolPath="$(CscToolPath)",
            TreatWarningsAsErrors="$(TreatWarningsAsErrors)",
            UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)",
            UseSharedCompilation="$(UseSharedCompilation)",
            Utf8Output="$(Utf8Output)",
            VsSessionGuid="$(VsSessionGuid)",
            WarningLevel="$(WarningLevel)",
            WarningsAsErrors="$(WarningsAsErrors)",
            WarningsNotAsErrors="$(WarningsNotAsErrors)",
            Win32Icon="$(ApplicationIcon)",
            Win32Manifest="$(Win32Manifest)",
            Win32Resource="$(Win32Resource)",
            OutputRefAssembly,
            PdbFile)
      // Only Applicable to the regular CoreCompile:
      // <ItemGroup>
      // <_CoreCompileResourceInputs Remove="@(_CoreCompileResourceInputs)" />
      // </ItemGroup>
      //
      // <CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''"/>
      if '$(OnXamlPreCompileErrorTarget)' != '':
        OnError(ExecuteTargets="$(OnXamlPreCompileErrorTarget)")
  PropertyGroup
    // Design-time builds require a newer version than 1.0 to succeed, so override back to inbox in that case
    if '$(CSharpCoreTargetsPath)' == '' or ('$(DesignTimeBuild)' == 'true' and $(CSharpCoreTargetsPath.Contains('Microsoft.Net.Compilers.1.0.0'))):
      CSharpCoreTargetsPath = $(RoslynTargetsPath)\Microsoft.CSharp.Core.targets
  Import "$(CSharpCoreTargetsPath)"
  // Import design time targets for Roslyn Project System. These are only available if Visual Studio is installed.
  // Import design time targets before the common targets, which import targets from Nuget.
  PropertyGroup
    if '$(CSharpDesignTimeTargetsPath)'=='':
      CSharpDesignTimeTargetsPath = $(MSBuildExtensionsPath)\Microsoft\VisualStudio\Managed\Microsoft.CSharp.DesignTime.targets
  if '$(CSharpDesignTimeTargetsPath)' != '' and Exists('$(CSharpDesignTimeTargetsPath)'):
    Import "$(CSharpDesignTimeTargetsPath)"
  Import "Microsoft.Common.targets"
  if ('$(TargetFrameworkVersion)' != 'v2.0' and '$(TargetFrameworkVersion)' != 'v3.0' and '$(TargetFrameworkVersion)' != 'v3.5') and Exists('$(MSBuildToolsPath)\Microsoft.ServiceModel.targets'):
    Import "$(MSBuildToolsPath)\Microsoft.ServiceModel.targets"
  Target _SetTargetFrameworkMonikerAttribute(
      BeforeTargets="GenerateTargetFrameworkMonikerAttribute")
    PropertyGroup
      if '$(TargetFrameworkMoniker)' != '' and '$(TargetingClr2Framework)' != 'true':
        TargetFrameworkMonikerAssemblyAttributeText =
          | // <autogenerated />
          | using System%3b
          | using System.Reflection%3b
          | [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute("$(TargetFrameworkMoniker)", FrameworkDisplayName = "$(TargetFrameworkMonikerDisplayName)")]
  PropertyGroup
    if '$(Utf8Output)' == '':
      Utf8Output = true
    // NoCompilerStandardLib maps to the compiler's /nostdlib option. By default we always
    // want that switch to be passed to the compiler so that either we or the user
    // provides the references
    // NoStdLib on the other hand indicates that the user doesn't want standard references
    // so only if NoStdLib isn't set to true, will we provide the standard references
    if '$(NoCompilerStandardLib)' == '':
      NoCompilerStandardLib = true
    if '$(BuildingInsideVisualStudio)' == 'true' and '$(ErrorEndLocation)' == '':
      ErrorEndLocation = true
    // When building inside VS, by default use the same language for compiler messages as VS itself does.
    if '$(BuildingInsideVisualStudio)' == 'true' and '$(PreferredUILang)' == '':
      PreferredUILang = $([System.Globalization.CultureInfo]::CurrentUICulture.Name)
  // Add any "automatic" compiler references that need to be resolved when NoCompilerStandardLib is set
  // but the user hasn't told us to not include standard references
  if '$(NoCompilerStandardLib)' == 'true' and '$(NoStdLib)' != 'true':
    ItemGroup
      // Note that unlike VB, C# does not automatically locate System.dll as a "standard library"
      // instead the reference is always passed from the project. Also, for mscorlib.dll
      // we need to provide the explicit location in order to avoid resolving from, e.g.,
      // {CandidateAssemblyFiles}.
      _ExplicitReference += "$(FrameworkPathOverride)\mscorlib.dll"
  if '$(MSBuildRuntimeType)' == 'Full' and exists('$([MSBuild]::GetToolsDirectory32())\..\..\..\Common7\IDE\CommonExtensions\Microsoft\ProjectServices\Microsoft.DesignTime.targets'):
    Import "$([MSBuild]::GetToolsDirectory32())\..\..\..\Common7\IDE\CommonExtensions\Microsoft\ProjectServices\Microsoft.DesignTime.targets"
  if '$(CustomAfterMicrosoftCSharpTargets)' != '' and Exists('$(CustomAfterMicrosoftCSharpTargets)'):
    Import "$(CustomAfterMicrosoftCSharpTargets)"
  if '$(ImportByWildcardAfterMicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportAfter'):
    Import "$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportAfter\*"
  if '$(ImportUserLocationsByWildcardAfterMicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportAfter'):
    Import "$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.CSharp.targets\ImportAfter\*"