Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphics files in .net standard 2.0 library do have have build action of "Resource" #81

Closed
dgxhubbard opened this issue Jun 5, 2018 · 13 comments · Fixed by #84
Closed

Comments

@dgxhubbard
Copy link

We have a few graphics files in .net standard 2.0 libraries, and .net 4.7.1 libraries. We are using
MSBuildSdkExtras in these libraries. All the libraries have been converted to the new project system. However, we we try to set the build action to "Resource" it
is not an available option in .net standard 2.0 libraries. I am not sure if this is an project system error or an
MSBuildSdkExtras.

@clairernovotny
Copy link
Collaborator

What are you trying to achieve? What platform does it work on?

@dgxhubbard
Copy link
Author

Right now it will work on windows. It has string resources and graphic resources and that's all that is in it.
In the future the string resources will be used for .net core apps

@clairernovotny
Copy link
Collaborator

Do you have a simple repro? I'm not familiar with that item type.

@dgxhubbard
Copy link
Author

dgxhubbard commented Jun 5, 2018

I left out the importance fact it is an image file in a folder.
Like a png or gif for instance

@dgxhubbard
Copy link
Author

If I switch the project type from .net standard 2.0 to .net 4.7.1 then the Resource option becomes available.

@dgxhubbard
Copy link
Author

Below is an example project. The project folder has a "graphics" folder with an image foo.png.
If the target framework is .net 4.7.1 then the build action "Resource" is available. If the target framework is .net standard 2.0 then build action "Resource" is not available in drop down.

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <TargetFramework>net471</TargetFramework>
    <AssemblyName>ImgResources</AssemblyName>
    <RootNamespace>ImgResources</RootNamespace>
  </PropertyGroup>
  
  <PropertyGroup>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>  
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>..\..\..\..\bin\Debug\</OutputPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>..\..\..\..\bin\Release\</OutputPath>
  </PropertyGroup>
  
  
  <ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="MSBuild.Sdk.Extras" Version="1.5.4" />
  </ItemGroup>
  
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  

  <Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />

</Project>

@clairernovotny
Copy link
Collaborator

What happens if you include <Resource Include="images\*.png" /> in an ItemGroup?

@Nirmal4G
Copy link
Contributor

Nirmal4G commented Jun 6, 2018

Resource seems to support WPF only, so you have to target .NETFramework.

@dgxhubbard
Copy link
Author

When target framework is .net standard and image is included using
an exception is thrown in the main application because it cannot find the resource. When the target framework is .net 4.7.1 everything works.

@Nirmal4G
Copy link
Contributor

Nirmal4G commented Jun 6, 2018

Can you give me msbuild.binlog files generated using msbuild /m /bl /t:Clean;Restore;Build with net471 and netstandard2.0

I can take a look into it.

@dgxhubbard
Copy link
Author

Thanks here they are.

net_standard_msbuild.txt
net_4_7_msbuild.txt

@Nirmal4G
Copy link
Contributor

Nirmal4G commented Jun 6, 2018

I've looked into it.

As I said Resource is supported only in .NETFramework projects and it's specifically created for WPF. It imports Microsoft.WinFx.targets that has FileClassification target and other targets in PrepareResourcesDependsOn property which handles files going to .g.resources before being merged into main assembly!

That said, If you want to embed the files into the assembly, you can use EmbeddedResource Item type instead of Resource. Will that work for you?

@dgxhubbard
Copy link
Author

We wound up using a target of .net 471 to get this working and it is a wpf application anyway so that should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants