question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet new strips our conditional compile code

See original GitHub issue

I have an AppDelegate.cs file in my project with the following code. It is being stripped out when dotnet new is executed. I have verified the code is present in my packed NuGet.

#if DEBUG
Comet.Reload.Init();
#if

Is there a way to escape this and protect it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
davidortinaucommented, Aug 26, 2019

Where is this documented? I looked for similar with no luck.

//-:cnd:noEmit
1reaction
dansiegelcommented, Aug 24, 2019

Yes @davidortinau you’ll need to escape it in your AppDelegate like the following:

//-:cnd:noEmit
            // Code for starting up the Xamarin Test Cloud Agent
#if DEBUG
            Xamarin.Calabash.Start();
#endif
//+:cnd:noEmit

Keep in mind that all of your conditional properties and groups in the csproj will also be stripped out if you do not escape them.

  <PropertyGroup>
<!--/-:cnd:noEmit -->
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<!--/+:cnd:noEmit -->
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{00000000-0000-0000-0000-000000000000}</ProjectGuid>
    <ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <OutputType>Exe</OutputType>
    <RootNamespace>Company.Project.Mobile.App.iOS</RootNamespace>
    <IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
    <AssemblyName>Company.Project.Mobile.App.iOS</AssemblyName>
    <NuGetPackageImportStamp></NuGetPackageImportStamp>
    <BuildIpa>True</BuildIpa>
  </PropertyGroup>
<!--/-:cnd:noEmit -->
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
    <DefineConstants>__UNIFIED__;__MOBILE__;__IOS__;DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <MtouchArch>i386, x86_64</MtouchArch>
    <MtouchLink>None</MtouchLink>
    <MtouchDebug>true</MtouchDebug>
  </PropertyGroup>
<!--/+:cnd:noEmit -->
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trimming options - .NET
Learn how to control trimming of self-contained apps.
Read more >
How can I conditionally compile my C# for Mono vs. ...
It seems to me that if you need to have Mono vs MS.NET differences, then you need to be making those decisions at...
Read more >
Visual Studio: Use Conditional Compilation to Control ...
I have heard it said that the use of conditional compilation is often a strong code “smell” indicating a potential area for redesign....
Read more >
Conditional Compilation - Elements Docs
Conditional compilation is applied based on the presence or lack of presence of named conditional defines. Defines are identifers that live in a...
Read more >
Conditional compilation for ignoring method calls with the ...
In this post I describe conditional compilation using. ... NET Framework, your library uses one code path, and when you compile for ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found