I have an issue with a C# project. When built from Visual Studio (or by using MSBuild from command-line), the project is compiled with no issue.
However, we are also working with TeamCity and the compilation fails:
[16:41:51][Step 1/1] (CoreCompile target) ->
[16:41:51][Step 1/1] AssemblyInfo.cs(4,12): error CS0246: The type or namespace name 'AssemblyVersionAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\BuildAgent\work\d567fa3cb4955788\src\PowerSaver.IO.Channel\PowerSaver.IO.Channel.csproj]
[16:41:51][Step 1/1] AssemblyInfo.cs(4,12): error CS0246: The type or namespace name 'AssemblyVersion' could not be found (are you missing a using directive or an assembly reference?) [C:\BuildAgent\work\d567fa3cb4955788\src\PowerSaver.IO.Channel\PowerSaver.IO.Channel.csproj]
[16:41:51][Step 1/1] AssemblyInfo.cs(5,12): error CS0246: The type or namespace name 'AssemblyInformationalVersionAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\BuildAgent\work\d567fa3cb4955788\src\PowerSaver.IO.Channel\PowerSaver.IO.Channel.csproj]
[16:41:51][Step 1/1] AssemblyInfo.cs(5,12): error CS0246: The type or namespace name 'AssemblyInformationalVersion' could not be found (are you missing a using directive or an assembly reference?) [C:\BuildAgent\work\d567fa3cb4955788\src\PowerSaver.IO.Channel\PowerSaver.IO.Channel.csproj]
[16:41:51][Step 1/1] AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'AssemblyFileVersionAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\BuildAgent\work\d567fa3cb4955788\src\PowerSaver.IO.Channel\PowerSaver.IO.Channel.csproj]
[16:41:51][Step 1/1] AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'AssemblyFileVersion' could not be found (are you missing a using directive or an assembly reference?) [C:\BuildAgent\work\d567fa3cb4955788\src\PowerSaver.IO.Channel\PowerSaver.IO.Channel.csproj]
[16:41:51][Step 1/1]
[16:41:51][Step 1/1] 0 Warning(s)
[16:41:51][Step 1/1] 6 Error(s)
I have found links to similar problems, but cannot solve my problem:
- https://github.com/MicrosoftDX/Dash/issues/2
- Source file 'Properties\AssemblyInfo.cs' could not be found
- Error CS0246: The type or namespace name 'AssemblyFileVersion' could not be found
Thanks in advance for your help.
EDIT (additional information):
- .NET Framework 4.6.1
- Visual Studio Community 2017 (15.5.6) (using .csproj new format, compiled with MSBuild)
- TeamCity Professional 2017.1.4 (build 47070) (no plugin used)
- The attributes mentioned in the error message are already defined in an AssemblyInfo.cs file
Cake script we use to build the project:
#tool "nuget:?package=xunit.runner.console"
#tool nuget:?package=GitVersion.CommandLine
#addin Cake.Incubator
// Build script arguments
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
// Build script parameters
var rootDir = Directory(".");
var distDir = Directory("./dist");
var outputDir = Directory("./output");
var solutionFile = "./PowerSaver.sln";
GitVersion versionInfo;
// Tasks
Task("Clean")
.Does(() =>
{
CleanDirectories ("./src/**/" + configuration + "/bin");
CleanDirectories ("./src/**/" + configuration + "/obj");
CleanDirectories ("./test/**/" + configuration + "/bin");
CleanDirectories ("./test/**/" + configuration + "/obj");
CleanDirectory(distDir);
CleanDirectory(outputDir);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solutionFile);
});
Task("Set-Version")
.Does(() =>
{
Information("Working directory: {0}", rootDir);
var isRunningOnTeamCity = BuildSystem.TeamCity.IsRunningOnTeamCity;
var gitVersionLog = rootDir + File("gitversion.log");
versionInfo = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = isRunningOnTeamCity,
RepositoryPath = rootDir,
LogFilePath = gitVersionLog
});
Information("Building PowerSaver WebApp version {0}", versionInfo.FullSemVer);
Information("Assembly semver {0}", versionInfo.AssemblySemVer);
Information("Full build meta {0}", versionInfo.FullBuildMetaData);
Information("Build meta padded {0}", versionInfo.BuildMetaDataPadded);
Information("Build meta {0}", versionInfo.BuildMetaData);
Information("Building version {0}", versionInfo.FullSemVer);
Information("Semver {0}", versionInfo.SemVer);
Information("LegacySemver {0}", versionInfo.LegacySemVer);
Information("NuGet version {0}", versionInfo.NuGetVersion);
Information("NuGet version v2 {0}", versionInfo.NuGetVersionV2);
if(isRunningOnTeamCity)
{
Information(
@"Environment:
PullRequest: {0}
Build Configuration Name: {1}
TeamCity Project Name: {2}",
BuildSystem.TeamCity.Environment.PullRequest.IsPullRequest,
BuildSystem.TeamCity.Environment.Build.BuildConfName,
BuildSystem.TeamCity.Environment.Project.Name
);
BuildSystem.TeamCity.SetBuildNumber(versionInfo.FullSemVer);
}
else
{
Information("Not running on TeamCity");
}
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Set-Version")
.Does(() =>
{
var settings = new MSBuildSettings {
Verbosity = Verbosity.Normal,
ToolVersion = MSBuildToolVersion.VS2017,
Configuration = configuration,
PlatformTarget = PlatformTarget.MSIL
}
.WithProperty("RunOctoPack", "true")
.WithProperty("OctoPackPackageVersion", versionInfo.NuGetVersionV2)
.WithProperty("OctoPackEnforceAddingFiles", "true")
.WithProperty("OctoPackNuGetExePath", "C:/Apps/nuget.exe");
MSBuild(solutionFile, settings);
});
Task("Copy-Packages")
.Does(() =>
{
var packageVersion = versionInfo.NuGetVersionV2;
var modules = new []
{
"PowerSaverCore"
};
foreach (var module in modules)
{
var directory = Directory("./src/" + module + "/obj/octopacked");
var packageFile = directory + File(module + "." + packageVersion + ".nupkg");
CopyFileToDirectory(packageFile, distDir);
}
});
Task("Package")
.IsDependentOn("Build")
.IsDependentOn("Copy-Packages");
Task("Run-Tests")
.Description("Executes xUnit tests")
.Does(() =>
{
// See https://github.com/cake-build/cake/issues/1577
var testProjects = GetFiles("./test/**/*UnitTests.csproj");
foreach(var testProject in testProjects)
{
DotNetCoreTool(testProject, "xunit", "-xml report.xml");
}
});
// Targets
Task("Default")
.IsDependentOn("Package")
.IsDependentOn("Run-Tests");
RunTarget(target);
Solution
The building script was creating an AssemblyInfo.cs file by itself. We just had to delete the existing AssemblyInfo.cs file.