error CS0430: The extern alias 'snh' was not specified in a /reference option [Up.UnitTests\obj\x64\Debug\Fakes\wsc\f.csproj] - microsoft-fakes

Unit test project Up.UnitTests fails during build, with this build errors
error CS0430: The extern alias 'snh' was not specified in a /reference option
error CS0234: The type or namespace name 'System' does not exist in the namespace 'snh' (are you missing an assembly reference?)
The type or namespace name 'System' does not exist in the namespace 'snh'
I am guessing the above errors are due to System.Net.Http. Is it anything to do with different versions? How to fix this issue. Any help would be appreciated.

I, also, ran into this CS0430 error. In my scenario, the issue came due to a dependency caused by updating NSubstitute. I updated my *.fakes file like below to add diagnostics and see that the issue was System.Net.Http like you observed.
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
<Assembly Name="ClassLibrary1"/>
</Fakes>
After this, I tried to find the root cause of the issue by slowly removing the new dependencies and found that when System.Threading.Tasks.Extensions Nuget reference was there I would get the build error. During the upgrade NSubstitute added the System.Threading.Tasks.Extensions. In your scenario, it may likely be a similar dependency issue that it is not directly related to System.Net.Http.
Update: I found this issue on the dotnet/sdk repo that fixes the issue. To your test project, add the following Directory.Build.targets.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrivateFakesAfterFacadesSwitch"
Condition="'$(ImplicitlyExpandNETStandardFacades)' == 'true' and $(AssemblyName.EndsWith('.Fakes'))"
AfterTargets="ImplicitlyExpandNETStandardFacades" DependsOnTargets="ImplicitlyExpandNETStandardFacades">
<ItemGroup Condition="'#(_NETStandardLibraryNETFrameworkLib)' != ''">
<SnhReference Include = "#(_NETStandardLibraryNETFrameworkLib)" Condition="'%(_NETStandardLibraryNETFrameworkLib.FileName)' == 'System.Net.Http'" />
<Reference Remove="%(SnhReference.FileName)" Condition="'#(SnhReference)' != ''"/>
<Reference Include="%(SnhReference.FileName)" Condition="'#(SnhReference)' != ''">
<HintPath>%(SnhReference.Identity)</HintPath>
<Private>false</Private>
<Aliases>snh</Aliases>
</Reference>
</ItemGroup>
</Target>
</Project>

Related

MSBUILD: "The target does not exist in the project." after modifying DependsOnTarget

After adding to .csproj
<PropertyGroup>
<CompileDependsOn>$(CompileDependsOn.ToString())</CompileDependsOn>
</PropertyGroup>
I'm getting error MSB4057: The target does not exist in the project.
error MSB4057: The target "CheckFileSystemCaseSensitive;
...other stuff...
;" does not exist in the project.
Nevertheless string between quotes looks correct.
Edit: Looks like duplication of strange behavior of Property functions
Like in accepted answer from https://stackoverflow.com/a/10024381/915546 solution is to use [MSBuild]::Unescape function:
<PropertyGroup>
<CompileDependsOn>$([MSBuild]::Unescape(CompileDependsOn.ToString()))</CompileDependsOn>
</PropertyGroup>

VSTS - Building ASP.NET Core 2.0, compile error: Could not locate the assembly "Microsoft.AspNetCore.Mvc.ViewFeatures"

VSTS build of my ASP.NET Core 2.0 MVC app fails with these warnings:
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.Mvc.ViewFeatures".
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Extensions.Logging.Abstractions". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Data.SqlClient". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
And then I get compilation error like these:
The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Error CS0246: The type or namespace name 'ILogger' could not be found (are you missing a using directive or an assembly reference?)
and so on for ILoggerFactory, SqlDataReader, etc. And everything builds perfectly on my machine locally. What am I missing?
First please make sure the PackageReference in .csproj are not refer the local paths. It should like:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
Then please use ASP.Net Core template to define your build definition:
With the .NET Core tasks to restore, build, test and publish, and you can also add other tasks for your needs.

Build csproj for MONO that requires dlls

I have a line of code that I got from a site called Zetcode, and in this to build the first example, I compile the code like this:
gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll 01-simple-cs-example.cs -out:simple-sample.exe
This builds the exe that draws my window, but I don't think my csproj file is correct.
<Project DefaultTargest="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- This Property will make a variable named MSBuildSample, then you can use it to
assign to whatever in the script.
Properties are variables inside the script.
-->
<SrcPath>src\</SrcPath>
<AssemblyName>01-simple-cs-example</AssemblyName>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
<!-- This Compile statement, gathers all the source files listed in an item called Compiled
ItemGroups interact with the source code.
-->
<Compile Include="$(SrcPath)01-simple-cs-example.cs" />
</ItemGroup>
<!-- In the Build target, the Inputs and Outputs targets which looks to see if the files have been updated,
or if the files are existent. If the files have not been changed, then the Build target is skipped.
-->
<Target Name="Build" Inputs="#(Compile)" Outputs="$(OutputPath)$(AssemblyName).exe" >
<!-- The MakeDir directive will create the directory in the property group above, if it meets the
condition stated in the Condition= statement.
-->
<Message Text="Creating the output path $(OutputPath)." />
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<!-- This Csc is the .NET C# compiler, which then uses the ItemGroup of collected sources called, Compile
-->
<Message Text="Compiling the source code." />
<Csc Sources="#(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
</Target>
</Project>
This is the result from trying to run xbuild, and msbuild.
C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example>xbuild
XBuild Engine Version 3.3.0.0
Mono, Version 3.3.0.0
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.
Build started 7/25/2014 2:47:41 PM.
__________________________________________________
Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" (default target(s)):
Target Build:
Created directory "bin\"
Tool C:\mono\Mono-3.2.3\bin\gmcs.bat execution started with arguments: /out:bin\01-simple-cs-example.exe src\01-simple-cs-example.cs
src\01-simple-cs-example.cs(1,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
src\01-simple-cs-example.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
src\01-simple-cs-example.cs(4,23): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
Task "Csc" execution -- FAILED
Done building target "Build" in project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj".-- FAILED
Done building project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj".-- FAILED
Build FAILED.
Errors:
C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj (default targets) ->
(Build target) ->
src\01-simple-cs-example.cs(1,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
src\01-simple-cs-example.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
src\01-simple-cs-example.cs(4,23): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
0 Warning(s)
3 Error(s)
Time Elapsed 00:00:01.5341534
This is the result from the MSBuild run. MSBuild completed successfully, but I imagine that's because MSBuild knows where to look without me having to specify it in the csproj file.
C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example>MSBuild
Microsoft (R) Build Engine version 4.0.30319.18408
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 7/25/2014 2:48:04 PM.
Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" on node 1 (default targets).
Build:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /out:bin\01-simple-cs-example.exe src\01-simple-cs-example.cs
Done Building Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:04.36
I don't know what to put into the csproj file to make it load those DLL's that I used in the command line to compile using gmcs. Any clues?
-- EDIT 2014-08-20 --
After using the answer from knocte, I was able to see how the References are added in a csproj file. Its as simple as adding an item group, and adding the References you listed with using in the C# source file.
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Drawing" />
<Reference Include="System" />
</ItemGroup>
This is the manual way to do it if you're building the csproj file manually.
Just use an IDE (MonoDevelop or Visual Studio) to add a GAC-reference to System.Windows.Forms and System.Drawing libraries.

error MSB4064: The "OverwriteReadOnlyFiles" parameter is not supported by the "Copy" task

I am using Msbuild 4.0. When i was using Msbuild 3.5 OverwriteReadonlyfiles worked without any issue.
But today when i was trying to use the copy task i am getting this issue.
error MSB4064:
The "OverwriteReadOnlyFiles" parameter is not supported
by the "Copy" t ask. Verify the parameter exists on the task, and it
is a settable public instance property.
This is my target which has copy task
<Target Name="CopyBOM">
<Copy SourceFiles="#(BOM)" DestinationFolder="%(BOM.Destination)" OverwriteReadOnlyFiles="true">
<Output TaskParameter="CopiedFiles" ItemName="CopyBOMFiles" />
</Copy>
<Message Text="Copied to BOM: #(CopyBOMFiles)"/>
</Target>
Following is the itemgroup i am using in my properties file
<BOM Include="..\..\..\Release\CoreDeployment.msi">
<Destination>..\..\..\Core\BOM\Comp1</Destination>
</BOM>
I am having multiple properties file, I have verified that in all the place Toolsversion=4.0 is placed.
Has any one faced this? Any way is there to solve this?
I'm using OverwriteReadOnlyFiles="true" without issues. Try to add ToolsVersion="4.0" into your Project tag:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
You are most likely dealing with a ToolsVersion issue, even though you say you've checked all your files and their imports. Omitting the ToolsVersion from a file will cause it to drop to a lower version, so if all you did was search for "ToolsVersion" you may have missed a file where it wasn't declared on the <Project> node at all.
Run a command line build with diagnostic level logging, with the following additional parameters:
> msbuild My.proj /fl /flp:v=diag;logfile=My.proj.diagnostic.log
After the build fails, open the log file, seach for "MSB4064" then backtrack up the file looking for anything specifying the 2.0 framework.

FxCop in MSBuild and disabling CA0060 exceptions

I am very new to MSBuild and it is taking me a little while to work out how to do things.
So I am trying to integrate FxCop into my project to be automatically run when I build them on the build server.
At the moment the way to go seems to be to add a custom task to the build that you call when you build. So I have so far created the following:
<Target Name="ExecuteFxCop">
<ItemGroup>
<Files Include="bin\XXXX.dll" />
</ItemGroup>
<!-- Call the task using a collection of files and all default rules -->
<MSBuild.ExtensionPack.CodeQuality.FxCop
TaskAction="Analyse"
Files="#(Files)"
SearchGac="True"
OutputFile="FxCopReport.xml">
</MSBuild.ExtensionPack.CodeQuality.FxCop>
</Target>
However when I run this >msbuild XXXX.csproj /t:ExecuteFxCop it fails with error 512 which I have narrowed down to an exception from indirectly-referenced assemblys:
<Exception Keyword="CA0060" Kind="Engine" TreatAsWarning="True">
<Type>Microsoft.FxCop.Sdk.FxCopException</Type>
<ExceptionMessage>The indirectly-referenced Silverlight assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' could not be found. This assembly is not required for analysis, however, analysis results could be incomplete. Silverlight reference assemblies should be specified with the '/reference' switch. This assembly was referenced by: XXX\bin\ESRI.ArcGIS.Client.dll.</ExceptionMessage>
</Exception>
But I cannot add this reference. Is there a way to get the build to see this reference or preferably just disable the error altogether?
I did try: http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/c6780439-bc04-459e-80c3-d1712b2f5456/ but it doesn't work
Try the work-around here: http://geekswithblogs.net/blachniet/archive/2011/07/12/avoiding-fxcop-warning-ca0060.aspx
Edit
For example, using the FxCop MsBuild task, set ContinueOnError and check the ExitCode as follows:
<Target Name="ExecuteFxCop">
<ItemGroup>
<Files Include="bin\XXXX.dll" />
</ItemGroup>
<!-- Call the task using a collection of files and all default rules -->
<MSBuild.ExtensionPack.CodeQuality.FxCop
TaskAction="Analyse"
Files="#(Files)"
SearchGac="True"
OutputFile="FxCopReport.xml"
ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="ExitCode"/>
</MSBuild.ExtensionPack.CodeQuality.FxCop>
<Error Condition="$(ExitCode) != 512" Text="FxCop failed with exit code: $(ExitCode)"/>
</Target>
P.S. (This is not tested)
Not sure if you're still looking for a solution but what usually works for me is adding the
fxcop cmd-option /d:{dir-of-random-assemblies}
which essentially tells fxcop to look in that additional directory for assemblies.
Adding a reference to a proj that doesn't need it is a bad idea in my opinion.
http://msdn.microsoft.com/en-US/library/bb429449(v=vs.80).aspx