admin管理员组文章数量:1395024
I have a program and a library. the program has to use windows-dependency (WinForms or WPF ...) but the library should be platform-agnostic. I also want to be .Net-Version agnostic. So my library .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net481;net9.0</TargetFrameworks>
</PropertyGroup>
</Project>
And the program .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net481-windows;net9.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestProjLib\TestProjLib.csproj" />
</ItemGroup>
</Project>
The full solution with this test-setup can be found in my GitHub-Repository:
- TestProjDep.sln
- TestProjDep/**
- TestProjLib/**
For .Net9.0 this system works and the program compiles just fine, but for .Net481 it fails with CS0009: Metafile : [...] not found.
When copying the files to the needed place I get:
NETSDK1005: The Ressourcefile "[...]\TestProjLib\obj\project.assets.json" has no target for "net481-windows" [...]
I already tried the following solutions:
- Library: net481-windows instead of net481 works, but then the library is platform-dependend.
- Library: using both net481 and net481-windows gives error: NETSDK1005
Is it a catch22 or is there a good stable solution ?
I have a program and a library. the program has to use windows-dependency (WinForms or WPF ...) but the library should be platform-agnostic. I also want to be .Net-Version agnostic. So my library .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net481;net9.0</TargetFrameworks>
</PropertyGroup>
</Project>
And the program .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net481-windows;net9.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestProjLib\TestProjLib.csproj" />
</ItemGroup>
</Project>
The full solution with this test-setup can be found in my GitHub-Repository:
https://github/joecare99/CSharp/tree/master/TestStatements
- TestProjDep.sln
- TestProjDep/**
- TestProjLib/**
For .Net9.0 this system works and the program compiles just fine, but for .Net481 it fails with CS0009: Metafile : [...] not found.
When copying the files to the needed place I get:
NETSDK1005: The Ressourcefile "[...]\TestProjLib\obj\project.assets.json" has no target for "net481-windows" [...]
I already tried the following solutions:
- Library: net481-windows instead of net481 works, but then the library is platform-dependend.
- Library: using both net481 and net481-windows gives error: NETSDK1005
Is it a catch22 or is there a good stable solution ?
Share Improve this question asked Feb 1 at 10:48 Joe CareJoe Care 1288 bronze badges 10 | Show 5 more comments1 Answer
Reset to default 1As Klaus Gütter pointed out, net481-windows
is not a valid MSBuild-target—even though it might work and the compiler seems to work normally?—it’s better to use net481
as the target. This applies to anyone who prefers the "new" .csproj
project file type.
Side note: I was surprised to find out that I had to change the "Main" project and not the library project.
Solution program .csproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net481;net9.0-windows</TargetFrameworks>
<!-- ^ here net481 instead of net481-windows -->
<UseWindowsForms>true</UseWindowsForms>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestProjLib\TestProjLib.csproj" />
</ItemGroup>
</Project>
This seems to work, after doing a lot of tests. More tests to do, but for now I am very thankful.
BTW: The example mentioned in the question has been reworked, and is working as expected.
本文标签:
版权声明:本文标题:CS0006-Error when referencing a library-project (C#, MSBuild, .Net, .csproj, NETSDK1005) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741878757a2402623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
netstandard2.0
. – Jonathan Dodds Commented Feb 1 at 18:27