Xamarin.Android app crashes after running Obfuscar (Visual Studio for Mac) - xamarin.android

I've got a basic Xamarin.Android project setup with Obfuscar configured
The obfuscar.xml:
<Obfuscator>
<Var name="RenameProperties" value="true" />
<Var name="RenameEvents" value="true" />
<Var name="RenameFields" value="true" />
<Var name="KeepPublicApi" value="false" />
<Var name="HidePrivateApi" value="true" />
<Var name="HideStrings" value="true" />
<Var name="UseUnicodeNames" value="true" />
<Var name="OptimizeMethods" value="true" />
<Var name="InPath" value="/Users/user1/Documents/dev/project/src/MyProject.Android/bin/Debug" />
<Var name="OutPath" value="$(InPath)/Obfuscator_Output" />
<Module file="$(InPath)/MyProject.dll" />
</Obfuscator>
And in the csproj file (I targeted Debug configuration to debug this issue):
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
<Message Importance="High" Text="Obfuscar task has been called." />
<Exec WorkingDirectory="$(MonoAndroidIntermediateAssetsDir)" Command="$(Obfuscar) $(ProjectDir)obfuscar.xml" />
<Copy SourceFiles="$(TargetDir)MyProject.dll" DestinationFolder="$(MonoAndroidIntermediateAssetsDir)" />
</Target>
Obfuscation does seem to work.. mapping.txt is generated and I see the following in the build logs:
Target AfterBuild:
Obfuscar task has been called.
mono /Users/user1/.nuget/packages/obfuscar/2.2.33/build/../tools/Obfuscar.Console.exe /Users/user1/Documents/dev/project/src/MyProject.Android/obfuscar.xml
Note that Rollbar API is enabled by default to collect crashes. If you want to opt out, please run with -s switch
Loading project /Users/user1/Documents/dev/project/src/MyProject.Android/obfuscar.xml...Processing assembly: Solo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Loading assemblies...Extra framework folders: Done.
Hiding strings...
Renaming: fields...Parameters...Properties...Events...Methods...Types...Done.
Saving assemblies...Done.
Writing log file...Done.
Completed, 10.76 secs.
Copying file from "/Users/user1/Documents/dev/project/src/MyProject.Android/bin/Debug/MyProject.dll" to "/Users/user1/Documents/dev/project/src/MyProject.Android/obj/Debug/android/assets/MyProject.dll".
However, when the app does run, it immediately crashes upon startup with:
System.IO.FileNotFoundException
Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.
Any ideas what's wrong with my configuration?

Related

Dotnet framework - Nlog configuration change using variable substitution in TFS cd pipeline

I have Nlog configuration in the web config file and I would like to change the file path in the CD pipeline in order to put some dynamic path based on the environment.
Right now the web.config file variable substitution (XML Variable Substitution option) does not support it.
What are the other ways this can be done? I really don't have a choice to go the Web.Config transformation approach.
Any guidance on this will really help.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="false"
internalLogLevel="Error" internalLogFile="c:\Logs\nlog-internal.log">
<targets name="nlogconfig" async="true">
<target xsi:type="File" name="name"
fileName="Path/${shortdate}.log"
archiveFileName="Path/${shortdate}.{###}.log"
layout="${longdate} ${uppercase:${level}} ${callsite:className=true:includeSourcePath=true:methodName=true:skipFrames=1:cleanNamesOfAnonymousDelegates=true} ${newline} ${message} ${newline} ${exception:innerFormat=ToString:maxInnerExceptionLevel=2:innerExceptionSeparator=newline:separator=newline:format=ToString,StackTrace}${newline}"
archiveAboveSize="8388608"
archiveNumbering="Rolling"
archiveEvery="Day"
concurrentWrites="true"
maxArchiveFiles="100" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="name" />
</rules>
</nlog>
What are the other ways this can be done?
You could use the Replace Token task from Replace Tokens Extension.
Here are my steps, you could refer to them:
Nlog configuration:
<targets>
<target name="logfile" xsi:type="File" fileName="#{variable}#/#{shortdate}#.log />
<target name="logconsole" xsi:type="Console" />
</targets>
Replace Token task sample:
- task: replacetokens#3
inputs:
rootDirectory: 'Folder Path'
targetFiles: '**/*.config'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: true
Variable:
Then the variables in Nlog configuration will be replaced.
Alternative solution is to deploy an environment-specific override-file next to the default NLog.config.
Example of environment-specific NLog.override.config:
<nlog>
<variable name="LogDirectory" value="D:/Path" />
</nlog>
Example of NLog.config:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="LogDirectory" value="${basedir}" /> <!-- Default Value -->
<include file="NLog.override.config" ignoreErrors="true" /> <!-- Override Value -->
<targets async="true">
<target xsi:type="File" name="name" fileName="${LogDirectory}/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="name" />
</rules>
</nlog>
The deployment-package could include multiple nlog.override.config-files. One for each environment and just deploy the right one based on chosen environment.
See also: https://github.com/nlog/nlog/wiki/Configuration-file#include-files

Concatenate using ANT

Im new to ANT:
Im trying to debug an ANT script which is concatenating followed by editing the same file recursively. when I try to run this, 5 out of 10 builds failed with the following error
java.io.FileNotFoundException:{PATH TO FILE}\file.xml (Access is denied)
I tried adding delay before and after each step.still, no luck
Any help here would be appreciated.
<target name="concatxml">
<sleep seconds="1" />
<echo message="Concatenating file..." />
<concat destfile="${location}/file.xml">
<filelist dir="." files="${loc1}/file1.xml,${loc2}/file2.xml" />
</concat>
<echo message="Concatenating completed" />
<sleep seconds="1" />
<echo message="doImportReq.xml is released for concatenating..." />
</target>
<target name="replacevalxml">
<sleep seconds="1" />
<echo message="Replace initiated" />
<replace file="${location}/file.xml" token="#DOMAIN#" value="${dev}" />
<echo message="...replace completed />
<sleep seconds="1" />
</target>
I noticed this:
files="${loc1}/file1.xml,{loc2}/file2.xml"
That should be ${loc2} and not {loc2}. I don't know if that's a problem or not...

Transform appSettings from external file after merge

What I'm trying to do is transform one of appSettings which is in external file:
Here is external.config
<?xml version="1.0"?>
<appSettings>
<add key="SomeKey" value="some value" />
</appSettings>
Web.config
<?xml version="1.0"?>
<configuration>
<appSettings file="..\..\external.config">
<add key="SomeKey1" value="some value 1" />
</appSettings>
</configuration>
Web.Debug.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="SomeKey" value="some changed value"xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
After build in proper configuration which in my example is Debug there's only this:
<?xml version="1.0"?>
<configuration>
<appSettings file="..\..\external.config">
<add key="SomeKey1" value="some value 1" />
</appSettings>
</configuration>
but it should be:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="SomeKey1" value="some value 1" />
<add key="SomeKey" value="some changed value"/>
</appSettings>
</configuration>
I tryed to make shared appSettings by 2 or more different project 1-st is WCF Service second ASP.NET MVC 4 Application
Edited:
I've tryed to move this file attribute to Web.Debug.config but it's as well doesn't work.
The question is:
How can i accomplish such thing?Is it even possible?
Interesting. I have the same issue like yours. So now here is a workaround for your reference.
Please open project file - XXX.csproj
for example, ISWB.Test.Unit.csproj
add below section like this
<!-- Rock Add here, 2015.03.19 enable the external config transformation -->
<Target Name="BeforeCompile" Condition="Exists('ISWB.$(Configuration).config')">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="ISWB.config" Destination="$(IntermediateOutputPath)ISWB.config" Transform="ISWB.$(Configuration).config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="ISWB.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)ISWB.config">
<TargetPath>ISWB.config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
<Target Name="AfterCompile" Condition="Exists('app.$(Configuration).config')">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Please notice the added section, you have to add it into cs project file in a TEXT editor manually.
Please replace ISWB with yours. And then save it.
it should work well.
Enjoy it!

Configuration of build.xml file for Sonar modules with Ant

I am setting up a Sonar project (using the delphi plugin), for simplicity sake assume there are two modules I want to report on.
Each module is in it's own sub-folder and each has it's own build.xml file.
At this point I can successfully run the sonar tasks and generate reports for each module as an independent project.
My problem is with configuring the "master" build.xml file.
The module build.xml file looks like this:
<?xml version="1.0"?>
<project name = "CRM" default = "sonar" basedir = ".">
<!-- Add the Sonar task -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<target name="sonar">
<property name="sonar.projectKey" value="EXO:CRM" />
<property name="sonar.host.url" value="http://localhost:9000" />
<sonar:sonar workDir="." key="CRM.key" version="0.1" xmlns:sonar="antlib:org.sonar.ant">
<property key="sonar.sources" value="." /> <!-- project sources directories (required) -->
<property key="sonar.language" value="delph" /> <!-- project language -->
<property key="sonar.delphi.codecoverage.excluded" value=".\tests" /> <!-- code coverage excluded directories -->
<property key="sonar.importSources" value="true" /> <!-- should we show sources or not? -->
<property key="sonar.delphi.sources.excluded" value="" /> <!-- excluded directories -->
<property key="sonar.delphi.sources.include" value=".\includes" /> <!-- include directories, "," separated -->
<property key="sonar.delphi.sources.include.extend" value="true" /> <!-- should we extend includes in files? -->
</sonar:sonar>
</target>
</project>
The "Master" build.xml looks like this:
<?xml version="1.0"?>
<project name = "EXO" default = "sonar" basedir = ".">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<target name="sonar">
<property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />
<sonar:sonar workDir="." key="EXO.key" version="0.1" xmlns:sonar="antlib:org.sonar.ant">
<!-- project sources directories (required) -->
<property key="sonar.sources" value="." />
<property key="sonar.language" value="delph" />
<property key="sonar.importSources" value="true" />
<property key="sonar.delphi.sources.excluded" value="" />
<property key="sonar.delphi.sources.include" value=".\includes" />
<property key="sonar.delphi.sources.include.extend" value="true" />
</sonar:sonar>
</target>
</project>
It is always scanning all sources (required value) i.e. it is not respecting my modules.
The only way I can get this to work currently is by limiting the source code like this
<property key="sonar.sources" value="./crm/,./exonet6000/" />
I'm sure I must be mis-configuring something obvious here.
EDIT: I have now what I believe is a more consistent set of files based on examples here https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/java-ant-modules
Master build file:
<?xml version="1.0" encoding="UTF-8"?>
<project name = "EXO" default = "sonar" basedir = "." xmlns:sonar="antlib:org.sonar.ant">
<echo>Root Project</echo>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<property name="sonar.host.url" value="http://localhost:9000" />
<property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />
<target name="sonar">
<sonar:sonar key="EXO.key" version="0.1">
</sonar:sonar>
</target>
</project>
and one of the submodule files
<?xml version="1.0" encoding="UTF-8"?>
<project name="CRM" default="all" basedir=".">
<echo>CRM Module</echo>
<property name="sonar.language" value="delph" />
<property name="sonar.projectKey" value="EXO:CRM" />
<property name="sonar.sources" value="." />
<target name="all" />
</project>
At this point the sonar process is completing successfully BUT no actual anlysis is being done. A key point is that I am not seeing the echo of the submodule so I suspect these build tasks are not actually running.
If you look at this sample project using Ant and multimodules, I'd say that you should not specify any property inside the tag in your master build.xml file, and let the submodules specify those properties.
I've got a project with many submodules. My sonar target looks like this:
<target name="sonar" depends="build.dependencies" description="collect code metrics">
<property name="m1" value="a/build.xml,b/build.xml,c/build.xml,d/build.xml"/>
... more properties defining modules...
<property name="sonar.modules" value="${m1},${m2},${m3},${m4},${m5},${m6}..."/>
<property name="sonar.projectName" value="MyProject"/>
<sonar:sonar key="my:project" version="${version}" xmlns:sonar="antlib:org.sonar.ant">
</sonar:sonar>
</target>
No property definitions in the sonar:sonar task at all, and it is working as I want it to.
Sources are defined in the submodule build.xml files. (Actually, in a base-build.xml that all our build.xml files include... but that's an Ant thing not directly related to Sonar.)

Msbuild and SLN unbindig

I want to unbind my sln file from TFS server and publish it on SVN is there any "easy" option to do this. It's easy to open sln and chose unbind option in Visual Studio, but does any one ever tried to automate this process? There is a solution to edit sln file using xmlpoke and deleting binding information, but is it safe?
I have some samples published on the MSDN Code Gallery for the TFS 2010 SDK that illustrate how to do this with MSBuild and the MSBuild Community Tasks. Here's a snippet of MSBuild script from the WorkItemObjectModel sample's WorkItemType.csproj file:
<Import Project="$(MSBuildExtensionsPath32)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<ItemGroup>
<SourceFiles
Include="$(SolutionDir)**/*.*"
Exclude="$(SolutionDir)Package/**/*.*;$(SolutionDir)**/bin/**/*.*;$(SolutionDir)**/obj/**/*.*;$(SolutionDir)**/internal.proj;$(SolutionDir)**/*.*scc;$(SolutionDir)$(SolutionName).zip">
<Visible>False</Visible>
</SourceFiles>
</ItemGroup>
<Target Name="AfterBuild" Condition="'$(Configuration)'=='Release'"
Inputs="#(SourceFiles)" Outputs="$(SolutionDir)$(SolutionName).zip">
<Delete
Files="$(SolutionDir)$(SolutionName).zip"
Condition="Exists('$(SolutionDir)$(SolutionName).zip')" />
<PropertyGroup>
<PackageDir>$(SolutionDir)Package\</PackageDir>
</PropertyGroup>
<MakeDir
Directories="$(PackageDir)" />
<Copy
SourceFiles="#(SourceFiles)"
DestinationFiles="$(PackageDir)%(RecursiveDir)%(Filename)%(Extension)" />
<Delete
Files="$(PackageDir)**/bin/**/*.*;$(PackageDir)**/obj/**/*.*" />
<RemoveDir
Directories="$(PackageDir)**/bin;$(PackageDir)**/obj" />
<Attrib
Files="#(PackageFiles)"
ReadOnly="false" />
<FileUpdate
Files="$(PackageDir)$(SolutionFileName)"
IgnoreCase="true"
Regex="^\s+GlobalSection\(TeamFoundationVersionControl\).+\n(\s*Scc.*\n)+\s+EndGlobalSection"
ReplacementText=" "
Multiline="true"
Singleline="false" />
<ItemGroup>
<ProjectFiles Include="$(PackageDir)**/*.*proj" />
</ItemGroup>
<FileUpdate
Files="#(ProjectFiles)"
Regex="<Scc[A-z]+>.+</Scc[A-z]+>"
ReplacementText=" " />
<ItemGroup>
<PackageFiles Include="$(PackageDir)**\*.*" />
</ItemGroup>
<Zip
Files="#(PackageFiles)"
WorkingDirectory="$(PackageDir)"
ZipFileName="$(SolutionDir)$(SolutionName).zip" />
<Delete
Files="#(PackageFiles)" />
<RemoveDir
Directories="$(PackageDir)" />
</Target>
In a nutshell, this script copies the source files to a temporary directory, removes the source control bindings from the solution and project files, then zips up the sources and finally deletes the temporary directory.

Resources