Closed iremezoff closed 4 years ago
Some other probably useful information derived from running dotnet build -v diag
:
14:43:36.834 1:7>C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly. [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: System.InvalidOperationException: PE image does not have metadata. [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at System.Reflection.PortableExecutable.PEReader.GetMetadataBlock() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.AssemblyInformation.CorePopulateMetadata() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.AssemblyInformation.get_Dependencies() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.AssemblyDependency.AssemblyMetadata..ctor(String path) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.AssemblyInformation.<>c.
b__12_0(String p) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func
2 valueFactory) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.AssemblyInformation.GetAssemblyMetadata(String path, ConcurrentDictionary2 assemblyMetadataCache, AssemblyNameExtension[]& dependencies, String[]& scatterFiles, FrameworkName& frameworkName) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.SystemState.GetAssemblyMetadata(String path, ConcurrentDictionary
2 assemblyMetadataCache, AssemblyNameExtension[]& dependencies, String[]& scatterFiles, FrameworkName& frameworkName) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ReferenceTable.GetUnifiedAssemblyMetadata(Reference reference, IEnumerable1& unifiedDependencies, String[]& scatterFiles) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ReferenceTable.FindDependenciesAndScatterFiles(Reference reference, List
1 newEntries) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ReferenceTable.FindAssociatedFiles() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure(IEnumerable1 remappedAssembliesValue, ITaskItem[] referenceAssemblyFiles, ITaskItem[] referenceAssemblyNames, List
1 exceptions) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, GetAssemblyPathInGac getAssemblyPathInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\devenv\repo\TestLibrary\TestLibrary.csproj] C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\devenv\repo\TestLibrary\TestLibrary.csproj] Done executing task "ResolveAssemblyReference" -- FAILED. (TaskId:136) 14:43:36.834 1:7>Done building target "ResolveAssemblyReferences" in project "TestLibrary.csproj" -- FAILED.: (TargetId:183) 14:43:36.835 1:7>Target "_CheckForCompileOutputs: (TargetId:184)" in file "C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets" from project "C:\devenv\repo\TestLibrary\TestLibrary.csproj" (target "_CleanGetCurrentAndPriorFileWrites" depends on it): Set Property: _DocumentationFileProduced=false Set Property: _DebugSymbolsProduced=false 14:43:36.835 1:7>Done building target "_CheckForCompileOutputs" in project "TestLibrary.csproj".: (TargetId:184) Target "_SGenCheckForOutputs" skipped, due to false condition; ('$(_SGenGenerateSerializationAssembliesConfig)' == 'On' or ('@(WebReferenceUrl)'!='' and '$(_SGenGenerateSerializationAssembliesConfig)' == 'Auto')) was evaluated as ('Off' == 'On' or (''!='' and 'Off' == 'Auto')). 14:43:36.835 1:7>Target "_CleanGetCurrentAndPriorFileWrites: (TargetId:185)" in file "C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets" from project "C:\devenv\repo\TestLibrary\TestLibrary.csproj" (target "_CleanRecordFileWrites" depends on it): Task "ReadLinesFromFile" (TaskId:137) Task Parameter:File=obj\Debug\netcoreapp3.1\TestLibrary.csproj.FileListAbsolute.txt (TaskId:137) Done executing task "ReadLinesFromFile". (TaskId:137) Task "ConvertToAbsolutePath" (TaskId:138) Done executing task "ConvertToAbsolutePath". (TaskId:138) Task "FindUnderPath" (TaskId:139) Task Parameter:Path=C:\devenv\repo\TestLibrary (TaskId:139) Task Parameter:UpdateToAbsolutePaths=True (TaskId:139) Comparison path is "C:\devenv\repo\TestLibrary". (TaskId:139) Done executing task "FindUnderPath". (TaskId:139) Task "FindUnderPath" (TaskId:140) Task Parameter:Path=bin\Debug\netcoreapp3.1\ (TaskId:140) Task Parameter:UpdateToAbsolutePaths=True (TaskId:140) Comparison path is "bin\Debug\netcoreapp3.1\". (TaskId:140) Done executing task "FindUnderPath". (TaskId:140) Task "FindUnderPath" (TaskId:141) Task Parameter:Path=obj\Debug\netcoreapp3.1\ (TaskId:141) Task Parameter:UpdateToAbsolutePaths=True (TaskId:141) Comparison path is "obj\Debug\netcoreapp3.1\". (TaskId:141) Done executing task "FindUnderPath". (TaskId:141) Task "RemoveDuplicates" (TaskId:142) Done executing task "RemoveDuplicates". (TaskId:142) 14:43:36.836 1:7>Done building target "_CleanGetCurrentAndPriorFileWrites" in project "TestLibrary.csproj".: (TargetId:185) 14:43:36.836 1:7>Target "_CleanRecordFileWrites: (TargetId:186)" in file "C:\Program Files\dotnet\sdk\3.1.402\Microsoft.Common.CurrentVersion.targets" from project "C:\devenv\repo\TestLibrary\TestLibrary.csproj" (target "CoreBuild" depends on it): Task "RemoveDuplicates" (TaskId:143) Done executing task "RemoveDuplicates". (TaskId:143) Task "MakeDir" (TaskId:144) Task Parameter:Directories=obj\Debug\netcoreapp3.1\ (TaskId:144) Done executing task "MakeDir". (TaskId:144) Task "WriteLinesToFile" (TaskId:145) Task Parameter:File=obj\Debug\netcoreapp3.1\TestLibrary.csproj.FileListAbsolute.txt (TaskId:145) Task Parameter:Overwrite=True (TaskId:145) Done executing task "WriteLinesToFile". (TaskId:145) 14:43:36.837 1:7>Done building target "_CleanRecordFileWrites" in project "TestLibrary.csproj".: (TargetId:186) 14:43:36.837 1:7>Done Building Project "C:\devenv\repo\TestLibrary\TestLibrary.csproj" (default targets) -- FAILED.
File Database.csproj.FileListAbsolute.txt from obj directory contains:
C:\devenv\repo\Database\bin\Debug\netcoreapp3.1\Database.deps.json C:\devenv\repo\Database\bin\Debug\netcoreapp3.1\Database.dacpac C:\devenv\repo\Database\obj\Debug\netcoreapp3.1\Database.csprojAssemblyReference.cache C:\devenv\repo\Database\obj\Debug\netcoreapp3.1\Database.AssemblyInfoInputs.cache C:\devenv\repo\Database\obj\Debug\netcoreapp3.1\Database.AssemblyInfo.cs C:\devenv\repo\Database\obj\Debug\netcoreapp3.1\Database.dacpac
File TestLibrary.csproj.FileListAbsolute.txt contains nothing.
@iremezoff Would you mind sharing the contents of both project files? Based on the errors it seems that the .dacpac
is being referenced from standard C# project which obviously isn't going to work.
@iremezoff Would you mind sharing the contents of both project files? Based on the errors it seems that the
.dacpac
is being referenced from standard C# project which obviously isn't going to work.
Sure. Both files are pretty simple
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Database\Database.csproj" />
</ItemGroup>
</Project>
Database's one:
<Project Sdk="MSBuild.Sdk.SqlProj/1.9.0">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SqlServerVersion>Sql130</SqlServerVersion>
</PropertyGroup>
<ItemGroup>
<SqlCmdVariable Include="DbType">
<DefaultValue>test</DefaultValue>
<Value>$(SqlCmdVar__1)</Value>
</SqlCmdVariable>
</ItemGroup>
</Project>
I started experiencing from using netstandard2.0, passed netcore2.2 and finished by netcore3.1
@iremezoff I'm wondering what you're expecting to happen here. You're trying to reference a SQL Database Project (that produces a .dacpac
) from a C# project. I can understand why that fails, because I can only reference .dll
's from a C# project. Why did you add the project reference from your library project?
The purpose is to have a .dacpac file in output directory of a c# project and further handle it through dacpac lib. Yes, I know about packaging but it doesn't suit to my case because I need relevant db structure.
Ah, I see. Perhaps you can try adding ReferenceOutputAssembly=False
as an attribute to the ProjectReference
element in your library project.
ReferenceOutputAssembly=False
Oh, interesting. I've added and got no errors as well as no .dacpac file in the library's output directory nor anywhere else beside own db-project. So far I'm not sure it's possible what I want to achieve.
What if you also explicitly add CopyToOutputDirectory=Always
to the ProjectReference
next to the ReferenceOutputAssembly=False
?
What if you also explicitly add
CopyToOutputDirectory=Always
to theProjectReference
next to theReferenceOutputAssembly=False
?
Solved.
Just added in parallel with your comment:
<ProjectReference Include="..\Database\Database.csproj" ReferenceOutputAssembly="False" OutputItemType="Content" CopyToOutputDirectory="Always">
Thanks so much for your time!
@ErikEJ @jeffrosenberg Do you think we should add this to the docs? Personally I prefer treating my .dacpac
's separately, but perhaps there are more people who would like to do this.
No, this seems to be quite one off.
Agreed, this seems like the sort of uncommon situation that one or two people might find via a Google search :-)
Okay. Then I'll go ahead and close this issue then ;).
For the record: I stumbled on the exact same issue, so thanks for leaving this here :-)
Context: I have a MSBuild.Sdk.SqlProj project and next to it a unit tests project that loads the resulting dacpac in a LocalDb so some assertions can be done on the structure.
My test project is referencing to MSBuild.Sdk.SqlProj/1.9.0-sdk-based project. Unfortunately the test project can not be built because of error below:
Database.dacpac' could not be opened -- An attempt was made to move the file pointer before the beginning of the file.
This is not a first error I got. Before the first one I got "file too small". I had added to db-project several new files and increased the size up to 100Kb from 2Kb, the project was built itself correctly and produces valid .dacpac file but it couldn't be referenced well.
My research has followed me to some issue with reading .dacpac file from the test project.
Also I got another error trying to build the test project from cli:
Build FAILED.