microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
565 stars 287 forks source link

How do I build these projects locally? #2178

Open OskarKlintrot opened 3 years ago

OskarKlintrot commented 3 years ago

Is this a document under https://docs.microsoft.com/en-us/azure/azure-monitor/ No

Does the document belong to this repo? If yes, please describe the issue and what you expect to see.

\

There is a few README.md-files, but they don't seem to be up to date. Ie the one for NETCORE says that you need VS 2017 and not VS 2019 as CONTRIBUTING.md says. I've installed all prerequisites for NETCORE but I still can't build ApplicationInsights.AspNetCore.sln:

image

Everything.sln is not pretty either when trying to build:

image

I also tried NETCORE/build.ps1 since that one doesn't require me to add MSBuild to the PATH (I'm lazy today) but that script just hangs. I have no clue what the difference is between buildDebug.cmd and build.ps1 btw.

\

I wish that at least there could be simple to follow step-by-step instructions on how to get everything building. Unless of course it's possible to get to a point where you can just simply open *.sln and build them. Atm the docs seem to be outdated and incorrect/incomplete.

cijothomas commented 3 years ago

@TimothyMothra Could you help? It seems the contrib and readme docs got out of date?

OskarKlintrot commented 3 years ago

Just let me know if I can be of any assistance!

TimothyMothra commented 3 years ago

Sorry for the confusion, those script files are likely out of date. I'm not aware of anyone using them.

There may be a dependency that I set up on day one and have long forgotten. Can you try to build this sln: https://github.com/microsoft/ApplicationInsights-dotnet/blob/develop/BASE/Microsoft.ApplicationInsights.sln This contains the base-most libraries, and if this doesn't compile, nothing else will.

There may be a root cause in your Error List that we can't see. Can you please turn off "Warnings" and change "Build + IntelliSense" to just "Build"? I'd like to see if that gives you a smaller list of errors that we can investigate.

OskarKlintrot commented 3 years ago

Unfortunately it doesn't make a difference changing to just "Build". I think the interesting part is right at the beginning of the build log when building the base solution:

Build started...
1>------ Build started: Project: Microsoft.ApplicationInsights (Microsoft.ApplicationInsights\Microsoft.ApplicationInsights), Configuration: Debug Any CPU ------
2>------ Build started: Project: ApplicationInsightsTypes, Configuration: Debug Any CPU ------
Error occurred while restoring NuGet packages: Invalid restore input. Missing required property 'Name'. Input files: C:\Users\oskar\Source\Repos\ApplicationInsights-dotnet\BASE\src\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.csproj.
2>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1004: Assets file 'C:\Users\oskar\Source\Repos\ApplicationInsights-dotnet\BASE\Test\Microsoft.ApplicationInsights.Test\ApplicationInsightsTypes\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
2>Done building project "ApplicationInsightsTypes.csproj" -- FAILED.
2>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1004: Assets file 'C:\Users\oskar\Source\Repos\ApplicationInsights-dotnet\BASE\Test\Microsoft.ApplicationInsights.Test\ApplicationInsightsTypes\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
2>Done building project "ApplicationInsightsTypes.csproj" -- FAILED.
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net452\Microsoft.ApplicationInsights.AssemblyInfo.cs(18,59,18,83): warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net46\Microsoft.ApplicationInsights.AssemblyInfo.cs(18,59,18,83): warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net46\Microsoft.ApplicationInsights.AssemblyInfo.cs(22,55,22,79): error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]]
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net452\Microsoft.ApplicationInsights.AssemblyInfo.cs(22,55,22,79): error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]]
1>Done building project "Microsoft.ApplicationInsights.csproj" -- FAILED.

My guess is that all the error CS0518: Predefined type 'System.String' is not defined or imported and error CS0246: The type or namespace name 'SuppressMessageAttribute' could not be found (are you missing a using directive or an assembly reference?) is because VS doesn't get anywhere. I've seen those before when changing Target Framework from .NET Framework to .NET Core or .NET Standard. That made VS very confused. I can restore all packages (at least it seems like it) with dotnet restore but I still get the same errors in the beginning, the first lines of the build log again:

Build started...
1>------ Build started: Project: Microsoft.ApplicationInsights (Microsoft.ApplicationInsights\Microsoft.ApplicationInsights), Configuration: Debug Any CPU ------
2>------ Build started: Project: ApplicationInsightsTypes, Configuration: Debug Any CPU ------
Error occurred while restoring NuGet packages: Invalid restore input. Missing required property 'Name'. Input files: C:\Users\oskar\Source\Repos\ApplicationInsights-dotnet\BASE\src\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.csproj.
2>ApplicationInsightsTypes -> C:\Users\oskar\Source\Repos\bin\Debug\Test\Microsoft.ApplicationInsights.Test\ApplicationInsightsTypes\net452\ApplicationInsightsTypes.dll
2>FilesToSign: C:\Users\oskar\Source\Repos\bin\Debug\Test\Microsoft.ApplicationInsights.Test\ApplicationInsightsTypes\net452\ApplicationInsightsTypes.dll; Microsoft400; MsSharedLib72
2>Internal_Logging is set to false.
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net46\Microsoft.ApplicationInsights.AssemblyInfo.cs(18,59,18,83): warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net46\Microsoft.ApplicationInsights.AssemblyInfo.cs(22,55,22,79): error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]]
1>Done building project "Microsoft.ApplicationInsights.csproj" -- FAILED.
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net452\Microsoft.ApplicationInsights.AssemblyInfo.cs(18,59,18,83): warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\net452\Microsoft.ApplicationInsights.AssemblyInfo.cs(22,55,22,79): error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]]
1>Done building project "Microsoft.ApplicationInsights.csproj" -- FAILED.
2>ApplicationInsightsTypes -> C:\Users\oskar\Source\Repos\bin\Debug\Test\Microsoft.ApplicationInsights.Test\ApplicationInsightsTypes\netstandard2.0\ApplicationInsightsTypes.dll
2>FilesToSign: C:\Users\oskar\Source\Repos\bin\Debug\Test\Microsoft.ApplicationInsights.Test\ApplicationInsightsTypes\netstandard2.0\ApplicationInsightsTypes.dll; Microsoft400; MsSharedLib72
2>Internal_Logging is set to false.
2>Internal_Logging is set to false.
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\netstandard2.0\Microsoft.ApplicationInsights.AssemblyInfo.cs(18,59,18,83): warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision
1>C:\Users\oskar\Source\Repos\obj\Debug\Microsoft.ApplicationInsights\netstandard2.0\Microsoft.ApplicationInsights.AssemblyInfo.cs(22,55,22,79): error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]]
1>Done building project "Microsoft.ApplicationInsights.csproj" -- FAILED.

This time the error list makes more sense:

image

TimothyMothra commented 3 years ago

Just an update: I've been able to reproduce your issue. The project compiles on my dev box and on our build server, but I get your exact error on my personal computer.

The version is specified in one of the *.props files. My initial thought is that the build isn't discovering these files. I need more time to investigate.

OskarKlintrot commented 3 years ago

@TimothyMothra Any progress?

TimothyMothra commented 3 years ago

Sorry, @OskarKlintrot I haven't had time to look into this. I should have some time later this week.

Let me share some details to hopefully unblock you... We have several *.props files to normalize most of the common settings for our projects. I assume that either the project is not discovering these files or the value for the version is incorrect.

The versions are defined here and you're free to override these values to test if that unblocks you: https://github.com/microsoft/ApplicationInsights-dotnet/blob/3822ab1c591298b4c0c00eb6a853265a180e8d70/.props/_GlobalStaticVersion.props#L36-L39

The props files are addressed from here: https://github.com/microsoft/ApplicationInsights-dotnet/blob/3822ab1c591298b4c0c00eb6a853265a180e8d70/Directory.Build.props#L17-L25

You can also enable more logs by changing this flag: https://github.com/microsoft/ApplicationInsights-dotnet/blob/3822ab1c591298b4c0c00eb6a853265a180e8d70/Directory.Build.props#L4-L7

TimothyMothra commented 3 years ago

@OskarKlintrot Have you gotten latest recently?

The reason I get this error on my personal computer is because I hadn't gotten latest in several months. When I compile I get a version number of "2.15.0.98091". We calculate the build number based on time since a hardcoded date, and we update that date after every stable release. The build number is a UInt16, so the max valid value for the build number is "65535".

Getting latest and rebuilding resolves the issue for me.

OskarKlintrot commented 3 years ago

@TimothyMothra I've got a new computer (well, reinstalled Windows) and if I try to just clone the project and build the base solution I get this:

Build started...
1>------ Build started: Project: Microsoft.ApplicationInsights (Microsoft.ApplicationInsights\Microsoft.ApplicationInsights), Configuration: Debug Any CPU ------
2>------ Build started: Project: ApplicationInsightsTypes, Configuration: Debug Any CPU ------
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
1>C:\Program Files\dotnet\sdk\5.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file 'C:\_repos\external\msft\ApplicationInsights-dotnet\BASE\src\Microsoft.ApplicationInsights\obj\project.assets.json' doesn't have a target for 'net46'. Ensure that restore has run and that you have included 'net46' in the TargetFrameworks for your project.
1>Done building project "Microsoft.ApplicationInsights.csproj" -- FAILED.
1>C:\Program Files\dotnet\sdk\5.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file 'C:\_repos\external\msft\ApplicationInsights-dotnet\BASE\src\Microsoft.ApplicationInsights\obj\project.assets.json' doesn't have a target for 'net452'. Ensure that restore has run and that you have included 'net452' in the TargetFrameworks for your project.
1>Done building project "Microsoft.ApplicationInsights.csproj" -- FAILED.

I don't remember if I had to install anything more than VS last time 🤔

sjmulder commented 3 years ago

I'm also getting a very large build version: 2.17.0.22312591115501388

Using this as a workaround:

diff --git a/.props/_GlobalStaticVersion.props b/.props/_GlobalStaticVersion.props
index 8c207db25..5d4065541 100644
--- a/.props/_GlobalStaticVersion.props
+++ b/.props/_GlobalStaticVersion.props
@@ -35,7 +35,7 @@

     <VersionPrefix>$(SemanticVersionMajor).$(SemanticVersionMinor).$(SemanticVersionPatch)</VersionPrefix>
     <VersionSuffix>$(PreReleaseMilestone)</VersionSuffix>
-    <AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>
+    <AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
     <FileVersion>$(AssemblyVersion)</FileVersion>
   </PropertyGroup>
github-actions[bot] commented 2 years ago

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

sjmulder commented 2 years ago

Please keep open if not addressed.

TimothyMothra commented 2 years ago

Hi @sjmulder, are you still having this issue? What OS are you using? What IDE are you using?

I've tested this on multiple Windows machines using Visual Studio without any issue. Additionally, we've migrated all of our builds and unit tests to GitHub Workflows without issue. GitHub Workflows uses the dotnet cli to build these projects.

Can you please review if you're able to build these projects using the cli? I would expect you could copy the commands from here: https://github.com/microsoft/ApplicationInsights-dotnet/blob/main/.github/workflows/build-and-test-BASE.yml

OskarKlintrot commented 2 years ago

@sjmulder's workaround worked for dotnet build but still no luck when building in VS. I got a message telling me that I needed dev pack for 4.5 which doesn't exist anymore. As far as I can tell 4.5.2 is the oldest framework version that AI supports and hence need a dev pack for. So, I still get some unrelated warnings and messages in VS. But at least I can do some work with dotnet build, yay!

TimothyMothra commented 2 years ago

@OskarKlintrot can you share the full error you're getting regarding 4.5?

OskarKlintrot commented 2 years ago
Here's the full error: Severity Code Description Project File Line Suppression State
Error MSB3644 The reference assemblies for .NETFramework,Version=v4.5 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks Xdt.Tests C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1217

It's several of those and for other versions, all of which should be installed. There is also a lot of these for different framework and dotnet versions:

Severity Code Description Project File Line Suppression State
Error NU1201 Project Microsoft.ApplicationInsights is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Project Microsoft.ApplicationInsights does not support any target frameworks. EventCounterCollector.Tests C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\EventCounterCollector\EventCounterCollector.Tests\EventCounterCollector.Tests.csproj 1

It looks like VS is failing to restore the packages. dotnet build is struggling a bit, after running dotnet test I had to run git clean -dfx to get dotnet build working again.

OskarKlintrot commented 2 years ago

Errors from dotnet build:

Build FAILED.

C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\DependencyCollector\DependencyCollector\obj\project.assets.json' doesn't have a target for 'net452'. Ensure that restore has run and that you have included 'net452' in the TargetFrameworks for your project. [C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\DependencyCollector\DependencyCollector\DependencyCollector.csproj]
C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\WindowsServer\WindowsServer\obj\project.assets.json' doesn't have a target for 'net452'. Ensure that restore has run and that you have included 'net452' in the TargetFrameworks for your project. [C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\WindowsServer\WindowsServer\WindowsServer.csproj]
C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\Web\Web\Web.csproj : error NU1201: Project Microsoft.ApplicationInsights is not compatible with net452 (.NETFramework,Version=v4.5.2). Project Microsoft.ApplicationInsights does not support any target frameworks.
C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\WEB\Src\Web\Web\Web.csproj : error NU1201: Project WindowsServer is not compatible with net452 (.NETFramework,Version=v4.5.2). Project WindowsServer does not support any target frameworks.
    0 Warning(s)
    4 Error(s)
TimothyMothra commented 2 years ago

@OskarKlintrot, I did find one test project that still had a net45. I'm upgrading it now #2529.

I'm curious to know if this resolves your issues. ~You can wait for #2529 to merge or checkout my branch tilee\xdt.~ This merged today, you should have it next time you get latest.

OskarKlintrot commented 2 years ago

Nice! That issue went away, just a few hundred errors left!

I have a bunch of these left:

Assets file 'C:\Users\oskar\source\repos\OskarKlintrot\ApplicationInsights-dotnet\BASE\src\Microsoft.ApplicationInsights\obj\project.assets.json' doesn't have a target for 'net452'. Ensure that restore has run and that you have included 'net452' in the TargetFrameworks for your project. 

and

Project Microsoft.ApplicationInsights is not compatible with net472 (.NETFramework,Version=v4.7.2). Project Microsoft.ApplicationInsights does not support any target frameworks.

The target frameworks are correct, if a project targets net452, it will complain about net452.

In VS it looks like nuget fails to restore any packages (not getting any reasons as to why though from the package manager output) but dotnet restore works as well as dotnet msbuild .\Microsoft.ApplicationInsights.Web.sln -t:Restore (I guess they are doing the exact same thing though, the msbuild boundled with VS seems to be a bit different than the one used be the dotnet cli).

TimothyMothra commented 2 years ago

I've never found a root cause for "project.assets.json" errors. I see them maybe once a month on my dev box and for me they go away by either restarting Visual Studio or in extreme cases running git clean -xfd.

And I've never encountered these errors in our build pipelines which leads me to think they're environmental.

I'm open to suggestions if you find a root cause!

Expecho commented 2 years ago

May I suggest removing the build cmd files and update the contributing guide, or is there still any use for them? I've tried them as well but to no avail before I stumbled upon this issue.

TimothyMothra commented 2 years ago

Hi @Expecho, most of the cmd files had been orphaned from older build systems. We went through several changes to our build infra and had not kept all these other files up to date. Not an excuse, just explaining why these files are in the repo. I removed these orphaned files today, and I'll work on an update to the contributing guide this week.

Are you still blocked? All of our projects build on GitHub, you can reference our builds here: https://github.com/microsoft/ApplicationInsights-dotnet/tree/main/.github/workflows

Expecho commented 2 years ago

Hi @Expecho, most of the cmd files had been orphaned from older build systems. We went through several changes to our build infra and had not kept all these other files up to date. Not an excuse, just explaining why these files are in the repo. I removed these orphaned files today, and I'll work on an update to the contributing guide this week.

Are you still blocked? All of our projects build on GitHub, you can reference our builds here: https://github.com/microsoft/ApplicationInsights-dotnet/tree/main/.github/workflows

@TimothyMothra Yeah well, I am using VS 2022, it gets stuck in a neverending loop trying to restore nuget packages, lots of NuGet errors like

NU1201: Project Microsoft.ApplicationInsights is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Project Microsoft.ApplicationInsights does not support any target frameworks.

Also errors like

 error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]] [C:\Sources\ApplicationInsights-dotnet\BASE\src\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.csproj]

I managed to fix some using the details of this issue and this issue.

After removing support for .net framework and only support netstandard2.0 I managed to be able to build the project locally using dotnet build. Visual Studio keeps getting stuck in some endless loop while restoring the NuGet packages.

TimothyMothra commented 2 years ago

Microsoft.ApplicationInsights is absolutely compatible with net5.0 via netstardard. I can't explain why you're seeing that error. https://github.com/microsoft/ApplicationInsights-dotnet/blob/92766878547151706353cbe5a916724e53b47199/BASE/src/Microsoft.ApplicationInsights/Microsoft.ApplicationInsights.csproj#L7

This is the one discussed above, the workaround is described here: https://github.com/microsoft/ApplicationInsights-dotnet/issues/2178#issuecomment-804049887 The math to compute our build number is failing, but I don't know what causes it. This doesn't repo on any machine I've tested including our build servers. https://github.com/microsoft/ApplicationInsights-dotnet/blob/92766878547151706353cbe5a916724e53b47199/.props/_GlobalStaticVersion.props#L39

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

OskarKlintrot commented 1 year ago

Not stale