When I send an HTTP request to the function, It shows this error on console output, and returns HTTP 500 status code without hitting the the break point of function's first line.
Executed 'Validate' (Failed, Id=548b4612-42f8-4e49-886a-da6888045c32,
Duration=343ms) System.Net.Primitives: Value cannot be null.
(Parameter 'host') An unhandled host error has occurred.
System.Net.Primitives: Value cannot be null. (Parameter 'host').
Function
[FunctionName("Validate")]
public async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] string req,
[SignalR(HubName = "PubSub")] IAsyncCollector<SignalRMessage> signalRMessageQueue)
{
...
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<RootNamespace>ZulaMobile.Lobby.StoreValidation</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.30" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.21" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\zulamobile-azure-lobby-common\zulamobile-azure-lobby-common.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Functions\CafeBazaar\" />
<Folder Include="Huawei\" />
</ItemGroup>
</Project>
I tried to reproduce the same issue but it worked fine at my end.
Followed by this MS DOC & demo GitHub project ,
Created a Signal IR in Azure portal .
Open the download folder from my VS Code-
And added the following packages into my local here is my .csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.6.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>
<ItemGroup>
<None Update="content\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
And make sure that you have added your connection string in your local settings.json which have to copy from portal from Azure signalIR > Keys>Connection string.
Here are some screenshot for reference output:
Note: If still facing the same issue you can try to Un install the Azure function V3 and install it again .
For more information please refer this SO THREAD .
Related
I need to work with HTMLAgilityPack and Newtonsoft.Json on my Azure function, and it has become a serious headache for me. Even after installing and referencing all the required packages via Nuget, multiple times over the course of many days, nothing seems to be working in my favor.
Below is a piece of my code for reference:
#r "HtmlAgilityPack"
using HtmlAgilityPack;
public static SiteMeta GetSiteMeta(string URL)
{
SiteMeta siteMeta = new SiteMeta();
string retImg = "", retDesc = "", retTitle = "", retKeywords = "";
var getHtmlDoc = new HtmlWeb(); // Need to use this function from HTMLAgility pack
var document = getHtmlDoc.Load(URL);
var metaTags = document.DocumentNode.SelectNodes("//meta");
if (metaTags != null)
{
foreach (var sitetag in metaTags)
{
if (sitetag.Attributes["property"] != null && sitetag.Attributes["content"] != null && sitetag.Attributes["property"].Value.ToLower() == "og:description")
{
retDesc = sitetag.Attributes["content"].Value;
}
}
}
}
I've tried https://stackoverflow.com/a/63048380/1584140 a couple of times and many other answers over Stackoverflow as well as other websites, but the only errors I see everywhere are:
run.csx(5,1): error CS0006: Metadata file 'HtmlAgilityPack' could not be found
run.csx(17,7): error CS0246: The type or namespace name 'HtmlAgilityPack' could not be found (are you missing a using directive or an assembly reference?)
run.csx(108,30): error CS0246: The type or namespace name 'HtmlWeb' could not be found (are you missing a using directive or an assembly reference?)
Similar thing happens with Newtonsoft.Json as well.
This is how my VS project looks like:
Edit July 10 2022: Adding content on .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="TimerTrigger1\run.csxc" />
</ItemGroup>
<ItemGroup>
<None Include="TimerTrigger1\function.proj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TimerTrigger1/function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TimerTrigger1/readme.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TimerTrigger1\run.csx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
I am trying to get some values from the appsettings.json. But whatever I try with the AdditionalTextsProvider doesn't work. Here is my code
IncrementalValuesProvider<AdditionalText> textFiles = context.AdditionalTextsProvider.Where(static file => file.Path.Contains("appsettings.json")); // tried many things here, like EndsWith(".json") etc..
IncrementalValuesProvider<(string name, string content)> namesAndContents = textFiles.Select((text, cancellationToken) => (name: Path.GetFileNameWithoutExtension(text.Path), content: text.GetText(cancellationToken)!.ToString()));
context.RegisterSourceOutput(namesAndContents, (spc, nameAndContent) =>
{
nameAndContent.content; //always empty
nameAndContent.name; //always empty
});
From the other hand, when I implement the ISourceGenerator (same solution, same projects) this line of code just works!
var file = context.AdditionalFiles.FirstOrDefault(x => x.Path.Contains("appsettings.json"));
The project which is referencing the code generator:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Scrutor" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\myproject\myproject.csproj" />
<ProjectReference Include="..\myproject.EFCore\myproject.EFCore.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="appsettings.json" />
</ItemGroup>
</Project>
Code generator project :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- Generates a package at build -->
<IncludeBuildOutput>false</IncludeBuildOutput> <!-- Do not include the generator as a lib dependency -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<!-- Generator dependencies -->
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup> <GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>
<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(PKGNewtonsoft_Json)\lib\netstandard2.0\Newtonsoft.Json.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>
<ItemGroup>
<!-- Package the generator in the analyzer directory of the nuget package -->
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<!-- Package the props file -->
</ItemGroup>
</Project>
If you combine the additional text provider with the compilation it works for me (inspired by this great post):
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var files = context.AdditionalTextsProvider
.Where(a => a.Path.EndsWith("appsettings.json"))
.Select((a, c) => (Path.GetFileNameWithoutExtension(a.Path), a.GetText(c)!.ToString()));
var compilationAndFiles = context.CompilationProvider.Combine(files.Collect());
context.RegisterSourceOutput(compilationAndFiles, (productionContext, sourceContext) => Generate(productionContext, sourceContext));
}
void Generate(SourceProductionContext context, (Compilation compilation, ImmutableArray<(string, string)> files) compilationAndFiles)
{
//emit generated files...
}
Update:
Tested again with Visual Studio 17.4. and combination with compilation seems not to be necessary anymore. Generator is called as expected when appsettings.json changes with only AdditionalTextsProvider registered.
I have tried replicate but everything works for me.
I define my source generator as this
namespace ConsoleAppSourceGenerator
{
[Generator]
public class TxtGenerator : IIncrementalGenerator
{
private static int counter;
public void Initialize(IncrementalGeneratorInitializationContext initContext)
{
IncrementalValuesProvider<AdditionalText> textFiles = initContext.AdditionalTextsProvider
.Where(static file => file.Path.EndsWith(".txt"));
IncrementalValuesProvider<(string name, string content)> namesAndContents = textFiles
.Select((text, cancellationToken) => (name: Path.GetFileNameWithoutExtension(text.Path), content: text.GetText(cancellationToken)!.ToString()));
initContext.RegisterSourceOutput(namesAndContents, (spc, nameAndContent) =>
{
spc.AddSource($"TxtFile.{nameAndContent.name}.g.cs", $#"
// Counter {Interlocked.Increment(ref counter)}
public static partial class TxtFile
{{
public const string {nameAndContent.name} = ""{nameAndContent.content}"";
}}");
});
}
}
}
and source generator project as this
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
</ItemGroup>
</Project>
Then in another project, where I have made a dummy foo.txt file I have
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConsoleAppSourceGenerator\ConsoleAppSourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="foo.txt"/>
</ItemGroup>
</Project>
If I through Visual Studio look at Dependencies->Analyzers->ConsoleAppSourceGenerator>TxtFile.foo.g.cs then it correctly increase the counter on every change I to in the file (see step 9).
I store generated files in path ConsoleApp/Generated/ConsoleAppSourceGenerator/ConsoleAppSourceGenerator.TxtGenerator and whenever I rebuild the project it correctly updates the files.
Have you remembered to add the [Generator] attribute to the IIncrementalGenerator?
Could you test this out and validates this doesn't either work for you?
"AdditionalFiles" in your consuming project file is the key to ensuring these files are captured by your source/incremental generator.
Found out that using a "<AdditionalFiles Include='...' />" is not necessary in some projects such as ASPNET Core projects for Source/IncrementalGenerators. The .cshtml files are included as additional files by default.
Also, file globbing patterns work with the "Include" parameter.
I'm trying to connect my azure function to my azure sql database. When trying connection.open() it gives the following error.
Executed 'ClientID2' (Failed, Id=22ad8465-45f5-4fff-ba90-f0ff7d0ee465,
Duration=5895ms) [2021-11-25T10:49:57.575Z] System.Private.CoreLib:
Exception while executing function: ClientID2.
Microsoft.Data.SqlClient: The type initializer for
'Microsoft.Data.SqlClient.TdsParser' threw an exception.
Microsoft.Data.SqlClient: Could not load file or assembly
'System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'.
The connection itself runs on .net 5.0 framework, but not in .net core 3.1 .
[FunctionName("ClientID2")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log)
{
string requestBody = string.Empty;
try
{
log.LogInformation("Function process");
using (SqlConnection connection = new SqlConnection(Environment.GetEnvironmentVariable("Connection_Database")))
{
connection.Open();
Packages installed
Can anyone point me in the right direction?
Best regards
EDIT:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<RootNamespace>Client_ID</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.30" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Local.Settings.Json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"Connection_Database": Connection string from azure sql database
}
}
I figured it out, but not sure if it is the correct way.
Had to put the System.Text.Encoding.CodePages.dll and System.Runtime.CompilerServices.Unsafe.dll directly in bin folder of project.
Next, according to this answer
I added to the .csproj the following
<ItemGroup>
<FunctionsPreservedDependencies Include="System.Text.Encoding.CodePages.dll" />
<FunctionsPreservedDependencies Include="System.Runtime.CompilerServices.Unsafe.dll" />
</ItemGroup>
And then it worked
I'm using ConfuserEx to obfuscate my app, but it requires whole .dll binary file.
So, is there a way to obfuscate it using cli and then pack it to single file, or
access binary before compressing it to single file, so i can obfuscate it
I tried to do exclude main binary by ExcludeFromSingleFile, but it didn't work
My .crproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>exe</OutputType>
<AssemblyName>jay-$(RuntimeIdentifier)</AssemblyName>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Update="$(AssemblyName).dll">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CloudFlareUtilities" Version="1.3.0" />
<PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="YamlDotNet" Version="9.1.4" />
</ItemGroup>
</Project>
You need to add it as a post-build event, for example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>exe</OutputType>
<AssemblyName>jay-$(RuntimeIdentifier)</AssemblyName>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<!-- runs: TheAppToPassItTo.exe "<path to dll>" -->
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="TheAppToPassItTo.exe "$(TargetPath)"" />
</Target>
<ItemGroup>
<PackageReference Include="CloudFlareUtilities" Version="1.3.0" />
<PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="YamlDotNet" Version="9.1.4" />
</ItemGroup>
</Project>
Edited To Add
So, it turns out that the new "single file" executable option doesn't build it's executable from the bin directory, but from the obj directory. This has to be a simple oversight from the .NET team. There are many times where you'd want to modify your executable code before packing it up. What you are asking for is not unreasonable.
We can accomplish this by implementing a kludge until this gets rectified. We will still use the "post-build" job, but we are going to do some string replacement to build the correct path to the executable you want to modify.
This is the new script:
#ECHO off
SET tp=$(TargetPath)
SET tp=%tp:\bin\=\obj\%
ECHO Target file to modify: %tp%
YourObfuscatorEngine.exe "%tp%"
This will get the target path, in my case it is:
D:\Repositories\Source\ConsoleApp2\ConsoleApp2\bin\Release\netcoreapp3.1\win-x64\ConsoleApp2.dll
Then we do a string replace. We replace \bin\ with \obj\. The path will then be:
D:\Repositories\Source\ConsoleApp2\ConsoleApp2\obj\Release\netcoreapp3.1\win-x64\ConsoleApp2.dll
Now when you call your obfuscator engine, it will modify the correct file.
Please keep in mind that if you turn on the PublishReadyToRun option, your path will change to:
D:\Repositories\Source\ConsoleApp2\ConsoleApp2\obj\Release\netcoreapp3.1\win-x64\R2R\ConsoleApp2.dll
Which will make this a tad more complicated. So just keep that in mind if you decide you want to do this.
At the end of the day, your post-build script will look like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>exe</OutputType>
<AssemblyName>jay-$(RuntimeIdentifier)</AssemblyName>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="#ECHO off
SET tp=$(TargetPath)
SET tp=%25tp:\bin\=\obj\%25
ECHO Target file to modify: %25tp%25
YourObfuscatorEngine.exe "%25tp%25"" />
</Target>
<ItemGroup>
<PackageReference Include="CloudFlareUtilities" Version="1.3.0" />
<PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="YamlDotNet" Version="9.1.4" />
</ItemGroup>
</Project>
if you only need to modify the file on publish, I suggest hooking into the publish pipeline:
<Target Name="ObfuscateAssembly" BeforeTargets="PrepareForPublish">
<Exec Command="some.exe %(IntermediateAssembly.FullPath)" />
</Target>
In case a larger process is needed, e.g. for this sample all dependencies need to be present for the obfuscator to work on all assemblies, an extended method of hooking into the build process would be after ComputeResolvedFilesToPublishList where the SDK figures out what files are needed to publish.
Here's the full example where the obfuscator works on all the assemblies in a directory:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<PublishReadyToRun>True</PublishReadyToRun>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>False</SelfContained>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<Target Name="CalculateObfuscationInputs" DependsOnTargets="_ComputeAssembliesToPostprocessOnPublish">
<PropertyGroup>
<ObfuscationDir>$(IntermediateOutputPath)obfuscation\</ObfuscationDir>
</PropertyGroup>
<ItemGroup>
<AssembliesToObfuscate Include="#(ResolvedFileToPublish->WithMetadataValue('PostprocessAssembly', 'true'))" />
<AssembliesToObfuscateTemporaryLocation Include="#(AssembliesToObfuscate->'$(ObfuscationDir)%(Filename)%(Extension)')" />
<_PdbsToObfuscateInput Include="#(AssembliesToObfuscate->'%(RelativeDir)%(Filename).pdb')" />
<PdbsToObfuscate Include="#(_PdbsToObfuscateInput)" RelativePath="%(_PdbsToObfuscateInput.Identity)" Condition="Exists(%(_PdbsToObfuscateInput.Identity))" />
<PdbsToObfuscateTemporaryLocation Include="#(PdbsToObfuscate->'$(ObfuscationDir)%(Filename)%(Extension)')" />
</ItemGroup>
<MakeDir Directories="$(ObfuscationDir)" />
</Target>
<Target Name="PrepareForObfuscation" Inputs="#(AssembliesToObfuscate);#(PdbsToObfuscate)" Outputs="#(AssembliesToObfuscateTemporaryLocation);#(PdbsToObfuscateTemporaryLocation)">
<Copy SourceFiles="#(AssembliesToObfuscate);#(PdbsToObfuscate)" DestinationFiles="#(AssembliesToObfuscateTemporaryLocation);#(PdbsToObfuscateTemporaryLocation)" SkipUnchangedFiles="True" />
</Target>
<Target Name="ObfuscateAssembly" AfterTargets="ComputeResolvedFilesToPublishList" DependsOnTargets="CalculateObfuscationInputs;PrepareForObfuscation">
<Exec Command="some-obfuscator.exe $(ObfuscationDir)" />
<ItemGroup>
<ResolvedFileToPublish Remove="#(AssembliesToObfuscate);#(PdbsToObfuscate)" />
<ResolvedFileToPublish Include="#(AssembliesToObfuscateTemporaryLocation);#(PdbsToObfuscateTemporaryLocation)" />
</ItemGroup>
</Target>
</Project>
I'm compiling a projet both for net462 and dotnetcore2.0.
I have set the net462;dotnetcore2.0
It seems to work but I need to load an embedded resource like this:
using (var stream = assembly.GetManifestResourceStream("Alcuin.Admin.Api.Beans.TypeTraduction.json"))
using (var reader = new StreamReader(stream))
result = reader.ReadToEnd();
It gives me back a null stream.
Here is my csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net462</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<None Remove="Beans\TypeTraduction.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Beans\TypeTraduction.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Common\Alcuin.Common.Basics\Alcuin.Common.Basics.csproj" />
<ProjectReference Include="..\..\..\..\Common\Alcuin.Common.Graph\Alcuin.Common.Graph.csproj" />
</ItemGroup>
</Project>
Does someone know how to make it work properly?
Thanks.
Nevermind... I just had to remove this section :
<ItemGroup>
<None Remove="Beans\TypeTraduction.json" />
</ItemGroup>
Problem solved.