Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

[Visual Studio] Referencing Functions Project (eg. Unit Testing) points to wrong path.

Open rawlukMike opened this issue 9 years ago • 12 comments

After update to Latest Stable Microsoft.NET.Sdk.Functions 1.0.0 build path of *.dll's changed from

\bin\Debug\net461 to \bin\Debug\net461\bin

Actually the folders are less messy (even though it looks very badly \bin\*\bin), BUT it breaks any other projects, that may be referencing Functions Project (like unit testing ones). They still look for dll in \net461 path.

This cause Visual Studio to throw error at building referencing project:

Error CS0006 : Metadata file '*\FunctionApp2\FunctionApp2\bin\Debug\net461\FunctionApp2.dll' could not be found

Not nicest fix is to reference not a project but *.dll file, and build Projects one by one.

rawlukMike avatar Aug 15 '17 12:08 rawlukMike

Same problem here

sharpcoder28 avatar Aug 15 '17 17:08 sharpcoder28

Same problem here too - we also tried to find a work around over the weekend, but also came to the conclusion that referencing the dll was the only workaround option for now, which brings about it's own problems in build,

TheeJamesLee avatar Aug 15 '17 17:08 TheeJamesLee

@vijayrkn Could you take a look? Another option is to go back to our previous system, where only the publish layout uses the extra 'bin' folder.

lindydonna avatar Aug 15 '17 22:08 lindydonna

I don't know how TargetPath var is created in VS project, but if you only fix that one to point to correct dir with extra bin/+ filename.dll, it should fix all problems.

Other easy way is to use post build action to copy bin/Debug/net461/bin/* one level up. It duplicate output dlls but at least project can be referred again.

On 16 Aug 2017 12:01 am, "Donna Malayeri" [email protected] wrote:

@vijayrkn https://github.com/vijayrkn Could you take a look? Another option is to go back to our previous system, where only the publish layout uses the extra 'bin' folder.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Azure/Azure-Functions/issues/441#issuecomment-322602011, or mute the thread https://github.com/notifications/unsubscribe-auth/AGsQWh0rCK66LGux6guQwx-8JUT0KGhqks5sYhUrgaJpZM4O3gNc .

rawlukMike avatar Aug 15 '17 22:08 rawlukMike

@rawlukMike - we do fix the TargetPath (https://github.com/Azure/azure-functions-vs-build-sdk/blob/5b29350d1bfaaefae6a287ea6019956001c35d2d/src/Microsoft.NET.Sdk.Functions/Targets/netstandard1.0/Microsoft.NET.Sdk.Functions.Build.targets#L138) to point to the correct location. Looks like this will not get called when functions project references a normal class lib. Let me check if I can apply the same target to non-function projects.

vijayrkn avatar Aug 15 '17 22:08 vijayrkn

This is an issue only when the referenced class lib project is not on the same project system as functions project. Work-around: https://github.com/vijayrkn-test/FunctionsProjectWithClassLib - this is a sample functions project that references an xunit project & mstest project and this builds fine.

vijayrkn avatar Aug 15 '17 23:08 vijayrkn

@vijayrkn I confirm that using new style of project works, but by default VS is creating different one.

Also when looking into macros section you can see that TargetPath is still broken (or at least not displayed there correctly), are you 100% sure the build targets are set correctly ? image

Thanks for help !

rawlukMike avatar Aug 16 '17 10:08 rawlukMike

Fixed this issue with this PR https://github.com/Azure/azure-functions-vs-build-sdk/pull/98.

Also added the following scenario coverage as part of building the functions sdk itself.

  1. Function app project with references to Classic class lib & Sdk style class lib
  2. Classic unit test project with reference to a sample Function app and running the tests from this project to make sure references from class lib project works.
  3. SDK style unit test projects (mstest and xunit) with reference to function app and running tests from these test projects to verify this works.

vijayrkn avatar Aug 18 '17 18:08 vijayrkn

@vijayrkn I can see that you've bumped the version to 1.0.2. 1.0.1 looks to have gone public on nuget yesterday. Do you know when 1.0.2 will be on the public nuget?

TheeJamesLee avatar Aug 18 '17 18:08 TheeJamesLee

@TheeJamesLee We've just released 1.0.2.

lindydonna avatar Aug 18 '17 19:08 lindydonna

Fixed in 1.0.2: https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions

lindydonna avatar Aug 18 '17 19:08 lindydonna

I tried to enable static code analysis for an Azure Function project but its failing due to the additional bin folder in the output path. Static Code Analysis is looking for the assemblies one directory up since I believe its using TargetPath directory which isn't updated to include the additional bin folder. Do you know if there's a workaround for this?

I enabled Static Code Analysis by editing the project file like so: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net461</TargetFramework> <RunCodeAnalysis>true</RunCodeAnalysis> <CodeAnalysisRuleSet>ExtendedDesignGuidelineRules.ruleset</CodeAnalysisRuleSet> </PropertyGroup> <ItemGroup>

amazinmoe avatar Oct 08 '17 20:10 amazinmoe